refactor: rename InvalidNumberOfChild to InvalidNumberOfChildrenError
This commit is contained in:
parent
bbc85a0b0f
commit
d5091be438
@ -1,25 +1,25 @@
|
||||
import { InvalidNumberOfChild } from '../../../src/data/errors/invalid-number-of-children';
|
||||
import { InvalidNumberOfChildrenError } from '../../../src/data/errors/invalid-number-of-children';
|
||||
|
||||
describe('InvalidNumberOfChild', () => {
|
||||
describe('InvalidNumberOfChildrenError', () => {
|
||||
describe('when error is created without comparison', () => {
|
||||
it('returns error message telling that need exactly given number of children', () => {
|
||||
const invalidNumberOfChild = new InvalidNumberOfChild('tag', 2, 1);
|
||||
const invalidNumberOfChildrenError = new InvalidNumberOfChildrenError('tag', 2, 1);
|
||||
|
||||
const result = invalidNumberOfChild.message;
|
||||
const result = invalidNumberOfChildrenError.message;
|
||||
|
||||
expect(result).toEqual("tag tag must have exactly 2 children. It's actually 1");
|
||||
});
|
||||
|
||||
it('returns name as InvalidNumberOfChild', () => {
|
||||
const invalidNumberOfChild = new InvalidNumberOfChild('tag', 2, 1);
|
||||
it('returns name as InvalidNumberOfChildrenError', () => {
|
||||
const invalidNumberOfChildrenError = new InvalidNumberOfChildrenError('tag', 2, 1);
|
||||
|
||||
const result = invalidNumberOfChild.name;
|
||||
const result = invalidNumberOfChildrenError.name;
|
||||
|
||||
expect(result).toEqual('InvalidNumberOfChild');
|
||||
expect(result).toEqual('InvalidNumberOfChildrenError');
|
||||
});
|
||||
|
||||
it('extends Error', () => {
|
||||
const result = new InvalidNumberOfChild('tag', 2, 1);
|
||||
const result = new InvalidNumberOfChildrenError('tag', 2, 1);
|
||||
|
||||
expect(result).toBeInstanceOf(Error);
|
||||
});
|
||||
@ -27,9 +27,9 @@ describe('InvalidNumberOfChild', () => {
|
||||
|
||||
describe('when error is created with comparison setted as at least', () => {
|
||||
it('returns error message telling that need exactly given number of children', () => {
|
||||
const invalidNumberOfChild = new InvalidNumberOfChild('tag', 4, 2, 'at least');
|
||||
const invalidNumberOfChildrenError = new InvalidNumberOfChildrenError('tag', 4, 2, 'at least');
|
||||
|
||||
const result = invalidNumberOfChild.message;
|
||||
const result = invalidNumberOfChildrenError.message;
|
||||
|
||||
expect(result).toEqual("tag tag must have at least 4 children. It's actually 2");
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import MathMLToLaTeX from '../src';
|
||||
import * as mathmlStrings from './mocks/mathmlStrings';
|
||||
import { InvalidNumberOfChild } from '../src/data/errors/invalid-number-of-children';
|
||||
import { InvalidNumberOfChildrenError } from '../src/data/errors/invalid-number-of-children';
|
||||
|
||||
describe('#convert', () => {
|
||||
describe('given math string with mi tag', () => {
|
||||
@ -323,11 +323,11 @@ describe('#convert', () => {
|
||||
});
|
||||
|
||||
describe('containing three children', () => {
|
||||
it('throws InvalidNumberOfChildren Error', () => {
|
||||
it('throws InvalidNumberOfChildrenError Error', () => {
|
||||
const mathml = mathmlStrings.mfracWithThreeChildren;
|
||||
|
||||
const result = () => MathMLToLaTeX.convert(mathml);
|
||||
expect(result).toThrow(new InvalidNumberOfChild('mfrac', 2, 3));
|
||||
expect(result).toThrow(new InvalidNumberOfChildrenError('mfrac', 2, 3));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -856,7 +856,7 @@ describe('#convert', () => {
|
||||
|
||||
const result = () => MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toThrowError(new InvalidNumberOfChild('mover', 2, 3));
|
||||
expect(result).toThrowError(new InvalidNumberOfChildrenError('mover', 2, 3));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -920,7 +920,7 @@ describe('#convert', () => {
|
||||
|
||||
const result = () => MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toThrow(new InvalidNumberOfChild('munderover', 3, 4));
|
||||
expect(result).toThrow(new InvalidNumberOfChildrenError('munderover', 3, 4));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1 +1 @@
|
||||
export { InvalidNumberOfChild } from './invalid-number-of-children';
|
||||
export { InvalidNumberOfChildrenError } from './invalid-number-of-children';
|
||||
|
@ -1,8 +1,8 @@
|
||||
export class InvalidNumberOfChild extends Error {
|
||||
export class InvalidNumberOfChildrenError extends Error {
|
||||
constructor(tagName: string, expectedNumberOfChild: number, currentNumberOfChild: number, comparison = 'exactly') {
|
||||
super(
|
||||
`${tagName} tag must have ${comparison} ${expectedNumberOfChild} children. It's actually ${currentNumberOfChild}`,
|
||||
);
|
||||
this.name = 'InvalidNumberOfChild';
|
||||
this.name = 'InvalidNumberOfChildrenError';
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter } from '../../../helpers/mathml-element-to-latex-converter';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
import { latexAccents } from '@/syntax/latex-accents';
|
||||
|
||||
export class GenericUnderOver implements ToLaTeXConverter {
|
||||
@ -15,7 +15,7 @@ export class GenericUnderOver implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChild(name, 2, childrenLength);
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChildrenError(name, 2, childrenLength);
|
||||
|
||||
const content = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const accent = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
import { ParenthesisWrapper, mathMLElementToLaTeXConverter } from '../../../helpers';
|
||||
|
||||
export class MFrac implements ToLaTeXConverter {
|
||||
@ -14,7 +14,7 @@ export class MFrac implements ToLaTeXConverter {
|
||||
const { children, name } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChild(name, 2, childrenLength);
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChildrenError(name, 2, childrenLength);
|
||||
|
||||
const num = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const den = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter, ParenthesisWrapper } from '../../../helpers';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
|
||||
export class MMultiscripts implements ToLaTeXConverter {
|
||||
private readonly _mathmlElement: MathMLElement;
|
||||
@ -14,7 +14,7 @@ export class MMultiscripts implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength < 3) throw new InvalidNumberOfChild(name, 3, childrenLength, 'at least');
|
||||
if (childrenLength < 3) throw new InvalidNumberOfChildrenError(name, 3, childrenLength, 'at least');
|
||||
|
||||
const baseContent = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter } from '../../../helpers';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
|
||||
export class MRoot implements ToLaTeXConverter {
|
||||
private readonly _mathmlElement: MathMLElement;
|
||||
@ -14,7 +14,7 @@ export class MRoot implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChild(name, 2, childrenLength);
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChildrenError(name, 2, childrenLength);
|
||||
|
||||
const content = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const rootIndex = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter, ParenthesisWrapper, BracketWrapper } from '../../../helpers';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
|
||||
export class MSub implements ToLaTeXConverter {
|
||||
private readonly _mathmlElement: MathMLElement;
|
||||
@ -14,7 +14,7 @@ export class MSub implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChild(name, 2, childrenLength);
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChildrenError(name, 2, childrenLength);
|
||||
|
||||
const base = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const subscript = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter, ParenthesisWrapper, BracketWrapper } from '../../../helpers';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
|
||||
export class MSubsup implements ToLaTeXConverter {
|
||||
private readonly _mathmlElement: MathMLElement;
|
||||
@ -14,7 +14,7 @@ export class MSubsup implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 3) throw new InvalidNumberOfChild(name, 3, childrenLength);
|
||||
if (childrenLength !== 3) throw new InvalidNumberOfChildrenError(name, 3, childrenLength);
|
||||
|
||||
const base = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const sub = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter, ParenthesisWrapper, BracketWrapper } from '../../../helpers';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
|
||||
export class MSup implements ToLaTeXConverter {
|
||||
private readonly _mathmlElement: MathMLElement;
|
||||
@ -14,7 +14,7 @@ export class MSup implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChild(name, 2, childrenLength);
|
||||
if (childrenLength !== 2) throw new InvalidNumberOfChildrenError(name, 2, childrenLength);
|
||||
|
||||
const base = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const exponent = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ToLaTeXConverter } from '@/domain/usecases/to-latex-converter';
|
||||
import { MathMLElement } from '../../../protocols/mathml-element';
|
||||
import { mathMLElementToLaTeXConverter } from '../../../helpers';
|
||||
import { InvalidNumberOfChild } from '../../../errors';
|
||||
import { InvalidNumberOfChildrenError } from '../../../errors';
|
||||
|
||||
export class MUnderover implements ToLaTeXConverter {
|
||||
private readonly _mathmlElement: MathMLElement;
|
||||
@ -14,7 +14,7 @@ export class MUnderover implements ToLaTeXConverter {
|
||||
const { name, children } = this._mathmlElement;
|
||||
const childrenLength = children.length;
|
||||
|
||||
if (childrenLength !== 3) throw new InvalidNumberOfChild(name, 3, childrenLength);
|
||||
if (childrenLength !== 3) throw new InvalidNumberOfChildrenError(name, 3, childrenLength);
|
||||
|
||||
const base = mathMLElementToLaTeXConverter(children[0]).convert();
|
||||
const underContent = mathMLElementToLaTeXConverter(children[1]).convert();
|
||||
|
Loading…
Reference in New Issue
Block a user