Skip to content

Commit 32cdad4

Browse files
committed
Class refactoring and cleanup.
1 parent 91f3225 commit 32cdad4

File tree

5 files changed

+93
-58
lines changed

5 files changed

+93
-58
lines changed

tests/json/ParserBussproofsRegInfTest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ParserBussproofsRegInfTest",
3-
"factory": "parserTest",
3+
"factory": "parserOutputTest",
44
"packages": [
55
"base",
66
"ams",
@@ -8067,4 +8067,4 @@
80678067
}
80688068
}
80698069
}
8070-
}
8070+
}

tests/json/ParserBussproofsRegProofsTest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ParserBussproofsRegProofsTest",
3-
"factory": "parserTest",
3+
"factory": "parserOutputTest",
44
"packages": [
55
"base",
66
"ams",
@@ -29032,4 +29032,4 @@
2903229032
}
2903329033
}
2903429034
}
29035-
}
29035+
}

tests/src/other-test.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,7 @@
1-
import {ParserJsonTest} from './parser-test.js';
21
import {JsonTest} from './test.js';
3-
import {Configuration} from '../node_modules/mathjax-full/js/input/tex/Configuration.js';
4-
import {CharacterMap} from '../node_modules/mathjax-full/js/input/tex/SymbolMap.js';
5-
import ParseMethods from '../node_modules/mathjax-full/js/input/tex/ParseMethods.js';
62
import ParseUtil from '../node_modules/mathjax-full/js/input/tex/ParseUtil.js';
73

84

9-
export class ParserMultirelTest extends ParserJsonTest {
10-
11-
constructor(json) {
12-
// Just some things bogus attributes for testing.
13-
new CharacterMap('shadow', ParseMethods.mathchar0mo, {
14-
sim: ['\u223C', {something: 'nothing'}],
15-
simeq: ['\u2243', {something: 'nothing'}],
16-
asymp: ['\u224D', {something: 'else'}],
17-
cong: ['\u224D', {anything: 'nothing'}],
18-
lesssim: ['\u2272', {lspace: '1pt'}],
19-
gtrsim: ['\u2278', {rspace: '1pt'}]
20-
});
21-
Configuration.create('multirel-test', {handler: {macro: ['shadow']}, priority: 4});
22-
super(json);
23-
this.packages = ['base', 'ams', 'multirel-test'];
24-
}
25-
26-
}
27-
28-
29-
export class ParserConfigMacrosTest extends ParserJsonTest {
30-
31-
constructor(json) {
32-
super(json);
33-
this.packages = ['base', 'configmacros'];
34-
Object.assign(this.settings, {macros:{}});
35-
}
36-
37-
runTest(name, input, expected, {macro, control}) {
38-
Object.assign(this.settings.macros, macro);
39-
super.runTest(name, control, expected);
40-
super.runTest(name, input, expected);
41-
}
42-
43-
}
44-
455
export class KeyvalTest extends JsonTest {
466

477
runTest(name, input, expected) {

tests/src/parser-test.js

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
import {mathjax} from '../node_modules/mathjax-full/js/mathjax.js';
22

33
import {TeX} from '../node_modules/mathjax-full/js/input/tex.js';
4-
import {SVG} from '../node_modules/mathjax-full/js/output/svg.js';
54
import {RegisterHTMLHandler} from "../node_modules/mathjax-full/js/handlers/html.js";
65
import {chooseAdaptor} from "../node_modules/mathjax-full/js/adaptors/chooseAdaptor.js";
76
import {JsonMmlVisitor} from '../node_modules/mathjax-full/js/core/MmlTree/JsonMmlVisitor.js';
87
import {STATE} from '../node_modules/mathjax-full/js/core/MathItem.js';
98

109
import {TagsFactory} from '../node_modules/mathjax-full/js/input/tex/Tags.js';
1110
import {MapHandler} from "../node_modules/mathjax-full/js/input/tex/MapHandler.js";
11+
import {AllPackages} from '../node_modules/mathjax-full/js/input/tex/AllPackages.js';
1212

1313
import {JsonTest, Test} from './test.js';
1414

15-
import {AllPackages} from '../node_modules/mathjax-full/js/input/tex/AllPackages.js';
16-
import '../node_modules/mathjax-full/js/input/tex/base/BaseConfiguration.js';
17-
import '../node_modules/mathjax-full/js/input/tex/ams/AmsConfiguration.js';
18-
1915
let fs = require('fs');
2016

2117
RegisterHTMLHandler(chooseAdaptor());
2218

19+
20+
/**
21+
* Parser tests from JSON input files.
22+
*/
2323
export class ParserJsonTest extends JsonTest {
2424

2525
packages = ['ams', 'base'];
2626
settings = {tags: 'none'};
2727
name = '';
2828

29+
/**
30+
* @override
31+
*/
2932
constructor(json) {
3033
super(json);
3134
this.packages = this.json['packages'] || this.packages;
@@ -46,18 +49,23 @@ export class ParserJsonTest extends JsonTest {
4649
}
4750
}
4851

52+
document(options) {
53+
return mathjax.document('<html></html>', {
54+
InputJax: new TeX(options)
55+
});
56+
}
4957

58+
/**
59+
* @override
60+
*/
5061
runTest(name, tex, expected, rest) {
5162
this.test(
5263
name,
5364
t => {
5465
mathjax.handleRetriesFor(function() {
5566
let options = {packages: this.packages};
5667
Object.assign(options, this.settings);
57-
let html = mathjax.document('<html></html>', {
58-
InputJax: new TeX(options), OutputJax: new SVG()
59-
});
60-
let root = html.convert(tex, {end: STATE.CONVERT});
68+
let root = this.document(options).convert(tex, {end: STATE.CONVERT});
6169
let jv = new JsonMmlVisitor();
6270
root.setTeXclass(null);
6371
let actual = jv.visitTree(root);
@@ -71,3 +79,69 @@ export class ParserJsonTest extends JsonTest {
7179
}
7280

7381
}
82+
83+
84+
import {SVG} from '../node_modules/mathjax-full/js/output/svg.js';
85+
86+
/**
87+
* Parser tests for packages that require an output jax.
88+
*/
89+
export class ParserOutputTest extends ParserJsonTest {
90+
91+
/**
92+
* @override
93+
*/
94+
document(options) {
95+
return mathjax.document('<html></html>', {
96+
InputJax: new TeX(options), OutputJax: new SVG()
97+
});
98+
}
99+
100+
}
101+
102+
import {Configuration} from '../node_modules/mathjax-full/js/input/tex/Configuration.js';
103+
import {CharacterMap} from '../node_modules/mathjax-full/js/input/tex/SymbolMap.js';
104+
import ParseMethods from '../node_modules/mathjax-full/js/input/tex/ParseMethods.js';
105+
106+
/**
107+
* Parser tests for multi relations method.
108+
*/
109+
export class ParserMultirelTest extends ParserJsonTest {
110+
111+
constructor(json) {
112+
// Just some things bogus attributes for testing.
113+
new CharacterMap('shadow', ParseMethods.mathchar0mo, {
114+
sim: ['\u223C', {something: 'nothing'}],
115+
simeq: ['\u2243', {something: 'nothing'}],
116+
asymp: ['\u224D', {something: 'else'}],
117+
cong: ['\u224D', {anything: 'nothing'}],
118+
lesssim: ['\u2272', {lspace: '1pt'}],
119+
gtrsim: ['\u2278', {rspace: '1pt'}]
120+
});
121+
Configuration.create('multirel-test', {handler: {macro: ['shadow']}, priority: 4});
122+
super(json);
123+
this.packages = ['base', 'ams', 'multirel-test'];
124+
}
125+
126+
}
127+
128+
129+
/**
130+
* Parser tests for macro configurations.
131+
*/
132+
export class ParserConfigMacrosTest extends ParserJsonTest {
133+
134+
constructor(json) {
135+
super(json);
136+
this.packages = ['base', 'configmacros'];
137+
Object.assign(this.settings, {macros:{}});
138+
}
139+
140+
runTest(name, input, expected, {macro, control}) {
141+
Object.assign(this.settings.macros, macro);
142+
super.runTest(name, control, expected);
143+
super.runTest(name, input, expected);
144+
}
145+
146+
}
147+

tests/src/test-factory.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import {ParserJsonTest} from './parser-test.js';
2-
import {KeyvalTest, ParserMultirelTest, ParserConfigMacrosTest} from './other-test.js';
1+
import * as pt from './parser-test.js';
2+
import {KeyvalTest} from './other-test.js';
33
import {JsonTest} from './test.js';
44
let fs = require('fs');
55

66
export class TestFactory {
77

88
static factory = {
99
'keyvalTest': KeyvalTest,
10-
'parserConfigMacros': ParserConfigMacrosTest,
11-
'parserMultirel': ParserMultirelTest,
12-
'parserTest': ParserJsonTest,
10+
'parserConfigMacros': pt.ParserConfigMacrosTest,
11+
'parserMultirel': pt.ParserMultirelTest,
12+
'parserOutput': pt.ParserOutputTest,
13+
'parserTest': pt.ParserJsonTest,
1314
'test': JsonTest
1415
}
1516

0 commit comments

Comments
 (0)