Skip to content

Commit f1942eb

Browse files
authored
Merge pull request #1443 from mathjax/tests/rewrite_remaining_xmlmatches
moves thests in ConfigMacros to use snapshots
2 parents 66a3ab2 + 46610ec commit f1942eb

File tree

3 files changed

+114
-54
lines changed

3 files changed

+114
-54
lines changed

testsuite/src/xmlMatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ expect.extend({
2424
* @param {string} received The string received from the tests
2525
* @param {string} expected The string expected to be produced by the tests
2626
*/
27-
export function toXmlMatch(received: string, expected: string) {
27+
function toXmlMatch(received: string, expected: string) {
2828
// This is slightly awkward way of getting around ts-jest problems with custom
2929
// matcher extensions.
3030
(expect(received) as any).toBeXmlMatch(expected);

testsuite/tests/input/tex/ConfigMacros.test.ts

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { beforeEach, describe, it } from '@jest/globals';
2-
import { toXmlMatch, setupTex, tex2mml } from '#helpers';
1+
import { beforeEach, describe, expect, it } from '@jest/globals';
2+
import { setupTex, tex2mml } from '#helpers';
33
import '#js/input/tex/configmacros/ConfigMacrosConfiguration';
44

55
beforeEach(() => {});
66

77
function runMacroTests(
88
macros: {[key: string]: any},
9-
expected: string,
109
control: string,
1110
macro: string) {
1211
setupTex(['base', 'configmacros'], macros);
13-
toXmlMatch(tex2mml(control), expected.replace('PH', control));
14-
toXmlMatch(tex2mml(macro), expected.replace('PH', macro));
12+
expect(tex2mml(control)).toMatchSnapshot();
13+
expect(tex2mml(macro)).toMatchSnapshot();
1514
}
1615

1716
/**********************************************************************************/
@@ -22,16 +21,7 @@ describe('Config Macros Active', () => {
2221
/********************************************************************************/
2322

2423
it('Macros Simple', () => {
25-
runMacroTests(
26-
{active: {"@": "~"}},
27-
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="PH" display="block">
28-
<mi data-latex="A">A</mi>
29-
<mtext data-latex="~">&#xA0;</mtext>
30-
<mi data-latex="a">a</mi>
31-
</math>`,
32-
'A~a',
33-
'A@a'
34-
);
24+
runMacroTests({active: {"@": "~"}}, 'A~a', 'A@a');
3525
});
3626

3727
/********************************************************************************/
@@ -46,31 +36,14 @@ describe('Config Macros Commands', () => {
4636
/********************************************************************************/
4737

4838
it('Commands Simple', () => {
49-
runMacroTests(
50-
{macros: {"RR": "{\\bf R}"}},
51-
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="PH" display="block">
52-
<mrow data-mjx-texclass="ORD" data-latex="{\\bf R}">
53-
<mi mathvariant="bold" data-latex="R">R</mi>
54-
</mrow>
55-
</math>`,
56-
'{\\bf R}',
57-
'\\RR'
58-
);
39+
runMacroTests({macros: {"RR": "{\\bf R}"}}, '{\\bf R}', '\\RR');
5940
});
6041

6142
/********************************************************************************/
6243

6344
it('Commands Argument', () => {
6445
runMacroTests(
6546
{macros: {"bold": ["{\\bf #1}", 1]}},
66-
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="PH" display="block">
67-
<mrow data-mjx-texclass="ORD" data-latex="{\\bf bold}">
68-
<mi mathvariant="bold" data-latex="b">b</mi>
69-
<mi mathvariant="bold" data-latex="o">o</mi>
70-
<mi mathvariant="bold" data-latex="l">l</mi>
71-
<mi mathvariant="bold" data-latex="d">d</mi>
72-
</mrow>
73-
</math>`,
7447
'{\\bf bold}',
7548
'\\bold{bold}'
7649
);
@@ -81,21 +54,6 @@ describe('Config Macros Commands', () => {
8154
it('Commands Aux Argument', () => {
8255
runMacroTests(
8356
{macros: {"foo": ["\\mbox{first } #1 \\mbox{ second } #2", 2, ["[", "]"]]}},
84-
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="PH" display="block">
85-
<mstyle displaystyle="false" data-latex="\\mbox{first }">
86-
<mtext>first&#xA0;</mtext>
87-
</mstyle>
88-
<mi data-latex="h">h</mi>
89-
<mi data-latex="i">i</mi>
90-
<mstyle displaystyle="false" data-latex="\\mbox{ second }">
91-
<mtext>&#xA0;second&#xA0;</mtext>
92-
</mstyle>
93-
<mi data-latex="t">t</mi>
94-
<mi data-latex="h">h</mi>
95-
<mi data-latex="e">e</mi>
96-
<mi data-latex="r">r</mi>
97-
<mi data-latex="e">e</mi>
98-
</math>`,
9957
'\\mbox{first } hi \\mbox{ second } there',
10058
'\\foo[hi]{there}'
10159
);
@@ -115,11 +73,6 @@ describe('Config Macros Environment', () => {
11573
it('Environment Simple', () => {
11674
runMacroTests(
11775
{environments: {"myHeartEnv": ["\\heartsuit", "\\spadesuit"]}},
118-
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\begin{myHeartEnv}a\\end{myHeartEnv}" display="block">
119-
<mi mathvariant="normal" data-latex="\\heartsuit">&#x2661;</mi>
120-
<mi data-latex="a">a</mi>
121-
<mi mathvariant="normal" data-latex="\\spadesuit">&#x2660;</mi>
122-
</math>`,
12376
'\\begin{myHeartEnv}a\\end{myHeartEnv}',
12477
'\\begin{myHeartEnv}a\\end{myHeartEnv}'
12578
);
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Config Macros Active Macros Simple 1`] = `
4+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="A~a" display="block">
5+
<mi data-latex="A">A</mi>
6+
<mtext data-latex="~">&#xA0;</mtext>
7+
<mi data-latex="a">a</mi>
8+
</math>"
9+
`;
10+
11+
exports[`Config Macros Active Macros Simple 2`] = `
12+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="A@a" display="block">
13+
<mi data-latex="A">A</mi>
14+
<mtext data-latex="~">&#xA0;</mtext>
15+
<mi data-latex="a">a</mi>
16+
</math>"
17+
`;
18+
19+
exports[`Config Macros Commands Commands Argument 1`] = `
20+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="{\\bf bold}" display="block">
21+
<mrow data-mjx-texclass="ORD" data-latex="{\\bf bold}">
22+
<mi mathvariant="bold" data-latex="b">b</mi>
23+
<mi mathvariant="bold" data-latex="o">o</mi>
24+
<mi mathvariant="bold" data-latex="l">l</mi>
25+
<mi mathvariant="bold" data-latex="d">d</mi>
26+
</mrow>
27+
</math>"
28+
`;
29+
30+
exports[`Config Macros Commands Commands Argument 2`] = `
31+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\bold{bold}" display="block">
32+
<mrow data-mjx-texclass="ORD" data-latex="{\\bf bold}">
33+
<mi mathvariant="bold" data-latex="b">b</mi>
34+
<mi mathvariant="bold" data-latex="o">o</mi>
35+
<mi mathvariant="bold" data-latex="l">l</mi>
36+
<mi mathvariant="bold" data-latex="d">d</mi>
37+
</mrow>
38+
</math>"
39+
`;
40+
41+
exports[`Config Macros Commands Commands Aux Argument 1`] = `
42+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\mbox{first } hi \\mbox{ second } there" display="block">
43+
<mstyle displaystyle="false" data-latex="\\mbox{first }">
44+
<mtext>first&#xA0;</mtext>
45+
</mstyle>
46+
<mi data-latex="h">h</mi>
47+
<mi data-latex="i">i</mi>
48+
<mstyle displaystyle="false" data-latex="\\mbox{ second }">
49+
<mtext>&#xA0;second&#xA0;</mtext>
50+
</mstyle>
51+
<mi data-latex="t">t</mi>
52+
<mi data-latex="h">h</mi>
53+
<mi data-latex="e">e</mi>
54+
<mi data-latex="r">r</mi>
55+
<mi data-latex="e">e</mi>
56+
</math>"
57+
`;
58+
59+
exports[`Config Macros Commands Commands Aux Argument 2`] = `
60+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\foo[hi]{there}" display="block">
61+
<mstyle displaystyle="false" data-latex="\\mbox{first }">
62+
<mtext>first&#xA0;</mtext>
63+
</mstyle>
64+
<mi data-latex="h">h</mi>
65+
<mi data-latex="i">i</mi>
66+
<mstyle displaystyle="false" data-latex="\\mbox{ second }">
67+
<mtext>&#xA0;second&#xA0;</mtext>
68+
</mstyle>
69+
<mi data-latex="t">t</mi>
70+
<mi data-latex="h">h</mi>
71+
<mi data-latex="e">e</mi>
72+
<mi data-latex="r">r</mi>
73+
<mi data-latex="e">e</mi>
74+
</math>"
75+
`;
76+
77+
exports[`Config Macros Commands Commands Simple 1`] = `
78+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="{\\bf R}" display="block">
79+
<mrow data-mjx-texclass="ORD" data-latex="{\\bf R}">
80+
<mi mathvariant="bold" data-latex="R">R</mi>
81+
</mrow>
82+
</math>"
83+
`;
84+
85+
exports[`Config Macros Commands Commands Simple 2`] = `
86+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\RR" display="block">
87+
<mrow data-mjx-texclass="ORD" data-latex="{\\bf R}">
88+
<mi mathvariant="bold" data-latex="R">R</mi>
89+
</mrow>
90+
</math>"
91+
`;
92+
93+
exports[`Config Macros Environment Environment Simple 1`] = `
94+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\begin{myHeartEnv}a\\end{myHeartEnv}" display="block">
95+
<mi mathvariant="normal" data-latex="\\heartsuit">&#x2661;</mi>
96+
<mi data-latex="a">a</mi>
97+
<mi mathvariant="normal" data-latex="\\spadesuit">&#x2660;</mi>
98+
</math>"
99+
`;
100+
101+
exports[`Config Macros Environment Environment Simple 2`] = `
102+
"<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\begin{myHeartEnv}a\\end{myHeartEnv}" display="block">
103+
<mi mathvariant="normal" data-latex="\\heartsuit">&#x2661;</mi>
104+
<mi data-latex="a">a</mi>
105+
<mi mathvariant="normal" data-latex="\\spadesuit">&#x2660;</mi>
106+
</math>"
107+
`;

0 commit comments

Comments
 (0)