test: add mroot InvalidNumberOfChildrenError case

This commit is contained in:
Alexandre Nunes 2020-10-03 11:07:31 -03:00
parent a907ab7328
commit 3c33d6a08f
2 changed files with 36 additions and 5 deletions

@ -340,6 +340,7 @@ describe('#convert', () => {
const mathml = mathmlStrings.shortMFrac; const mathml = mathmlStrings.shortMFrac;
const result = MathMLToLaTeX.convert(mathml); const result = MathMLToLaTeX.convert(mathml);
expect(result).toMatch('1/\\left(x^{3} + 3\\right)'); expect(result).toMatch('1/\\left(x^{3} + 3\\right)');
}); });
}); });
@ -349,20 +350,34 @@ describe('#convert', () => {
const mathml = mathmlStrings.mfracWithThreeChildren; const mathml = mathmlStrings.mfracWithThreeChildren;
const result = () => MathMLToLaTeX.convert(mathml); const result = () => MathMLToLaTeX.convert(mathml);
expect(result).toThrow(new InvalidNumberOfChildrenError('mfrac', 2, 3)); expect(result).toThrow(new InvalidNumberOfChildrenError('mfrac', 2, 3));
}); });
}); });
}); });
describe('given math string with mroot containing two content', () => { describe('given math string with mroot', () => {
describe('containing two content', () => {
it('convert mroot tag wrapping its contents inside \\sqrt command and root parameter', () => { it('convert mroot tag wrapping its contents inside \\sqrt command and root parameter', () => {
const mathml = mathmlStrings.mroot; const mathml = mathmlStrings.mroot;
const result = MathMLToLaTeX.convert(mathml); const result = MathMLToLaTeX.convert(mathml);
expect(result).toMatch('\\sqrt[3]{x + 2}'); expect(result).toMatch('\\sqrt[3]{x + 2}');
}); });
}); });
describe('containing three children', () => {
it('throw InvalidNumberOfChildrenError', () => {
const mathml = mathmlStrings.mrootWithThreeChildren;
const result = () => MathMLToLaTeX.convert(mathml);
expect(result).toThrow(new InvalidNumberOfChildrenError('mroot', 2, 3));
});
});
});
describe('given math string with mpadded tag', () => { describe('given math string with mpadded tag', () => {
it('convert mpadded just wrapping its content', () => { it('convert mpadded just wrapping its content', () => {
const mathml = mathmlStrings.mpadded; const mathml = mathmlStrings.mpadded;

@ -710,6 +710,22 @@ export const mroot = `
</root> </root>
`; `;
export const mrootWithThreeChildren = `
<root>
<math>
<mroot>
<mrow>
<mi>x</mi>
<mo>+</mo>
<mi>2</mi>
</mrow>
<mn>3</mn>
<mn>2</mn>
</mroot>
</math>
</root>
`;
export const mpadded = ` export const mpadded = `
<root> <root>
<math> <math>