11import { mathjax } from '../node_modules/mathjax-full/js/mathjax.js' ;
22
33import { TeX } from '../node_modules/mathjax-full/js/input/tex.js' ;
4- import { SVG } from '../node_modules/mathjax-full/js/output/svg.js' ;
54import { RegisterHTMLHandler } from "../node_modules/mathjax-full/js/handlers/html.js" ;
65import { chooseAdaptor } from "../node_modules/mathjax-full/js/adaptors/chooseAdaptor.js" ;
76import { JsonMmlVisitor } from '../node_modules/mathjax-full/js/core/MmlTree/JsonMmlVisitor.js' ;
87import { STATE } from '../node_modules/mathjax-full/js/core/MathItem.js' ;
98
109import { TagsFactory } from '../node_modules/mathjax-full/js/input/tex/Tags.js' ;
1110import { 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
1313import { 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-
1915let fs = require ( 'fs' ) ;
2016
2117RegisterHTMLHandler ( chooseAdaptor ( ) ) ;
2218
19+
20+ /**
21+ * Parser tests from JSON input files.
22+ */
2323export 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+
0 commit comments