From 91f322514aaad8e5dc66c21b782d7a8f5ac29ae9 Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 8 Oct 2020 17:20:31 +0100 Subject: [PATCH 1/3] Moves keyval tests to json format. --- tests/json/KeyvalTest.json | 170 ++++++++++++++++++++++++ tests/src/other-test.js | 19 +++ tests/src/parser-test.js | 65 ---------- tests/src/test-factory.js | 3 +- tests/src/tex-keyval-tests.js | 234 ---------------------------------- tests/tests.sh | 3 +- 6 files changed, 193 insertions(+), 301 deletions(-) create mode 100644 tests/json/KeyvalTest.json delete mode 100644 tests/src/tex-keyval-tests.js diff --git a/tests/json/KeyvalTest.json b/tests/json/KeyvalTest.json new file mode 100644 index 0000000..b89a821 --- /dev/null +++ b/tests/json/KeyvalTest.json @@ -0,0 +1,170 @@ +{ + "name": "KeyvalTest", + "factory": "keyvalTest", + "tests": { + "Keyval Trival": { + "input": "key={{}}", + "expected": {"key": true} + }, + "Keyval Trivial 2": { + "input": "key1={{}},key2={{{{}}}}", + "expected": {"key1": true, "key2": true} + }, + "Keyval Trival3": { + "input": "key={{}{}}", + "expected": {"key": "{}{}"} + }, + "Keyval Trivial 4": { + "input": "key1= { { } },key2= {{ { { }} } }", + "expected": {"key1": true, "key2": true} + }, + "Keyval Single": { + "input": "key=a", + "expected": {"key": "a"} + }, + "Keyval Double": { + "input": "key1=a,key2=b", + "expected": {"key1": "a", "key2": "b"} + }, + "Keyval Space": { + "input": "key1 = a , key2 = b", + "expected": {"key1": "a", "key2": "b"} + }, + "Keyval Single True": { + "input": "key1", + "expected": {"key1": true} + }, + "Keyval Double True": { + "input": "key1,key2", + "expected": {"key1": true, "key2": true} + }, + "Keyval Mixed": { + "input": "key1=a,key2,key3=c", + "expected": {"key1": "a", "key2": true, "key3": "c"} + }, + "Keyval Empty Comma Begin": { + "input": ",key1=a,key2,key3=c", + "expected": {"key1": "a", "key2": true, "key3": "c"} + }, + "Keyval Empty Comma Mid": { + "input": "key1=a,,key2,key3=c", + "expected": {"key1": "a", "key2": true, "key3": "c"} + }, + "Keyval Empty Comma End": { + "input": "key1=a,key2,key3=c,", + "expected": {"key1": "a", "key2": true, "key3": "c"} + }, + "Keyval Empty Comma Multi": { + "input": ",,key1=a,,,,key2,key3=c,,", + "expected": {"key1": "a", "key2": true, "key3": "c"} + }, + "Keyval Braces": { + "input": "key1={a},key2=b", + "expected": {"key1": "a", "key2": "b"} + }, + "Keyval Braces 2": { + "input": "key1={{a}},key2=b", + "expected": {"key1": "a", "key2": "b"} + }, + "Keyval Braces 3": { + "input": "key1={{{a}}},key2=b", + "expected": {"key1": "a", "key2": "b"} + }, + "Keyval Braces Comma": { + "input": "key1={a,b,c},key2=b", + "expected": {"key1": "a,b,c", "key2": "b"} + }, + "Keyval Braces Equal": { + "input": "key1={a=c},key2=b", + "expected": {"key1": "a=c", "key2": "b"} + }, + "Keyval Braces Comma Equal": { + "input": "key1={a=c,b},key2=b", + "expected": {"key1": "a=c,b", "key2": "b"} + }, + "Keyval Braces Simple 1": { + "input": "key1={{a}}", + "expected": {"key1": "a"} + }, + "Keyval Braces Simple 2": { + "input": "key1={{a{b}}}", + "expected": {"key1": "a{b}"} + }, + "Keyval Braces Simple 3": { + "input": "key1={{a={b}}}", + "expected": {"key1": "a={b}"} + }, + "Keyval Braces Prefix": { + "input": "key1={{}a}", + "expected": {"key1": "{}a"} + }, + "Keyval Braces Prefix 2": { + "input": "key1={{{}}a}", + "expected": {"key1": "{{}}a"} + }, + "Keyval Braces Prefix 3": { + "input": "key1={{}{}a}", + "expected": {"key1": "{}{}a"} + }, + "Keyval Braces Prefix 4": { + "input": "key1={{{}{}a}}", + "expected": {"key1": "{}{}a"} + }, + "Keyval Braces Prefix 5": { + "input": "key1={{}{a}}", + "expected": {"key1": "{}{a}"} + }, + "Keyval Braces Prefix 6": { + "input": "key1={{{}}{a}}", + "expected": {"key1": "{{}}{a}"} + }, + "Keyval Braces Mixed 1": { + "input": "key1={{a},{b}},key2=b", + "expected": {"key1": "{a},{b}", "key2": "b"} + }, + "Keyval Braces Mixed 2": { + "input": "key1={{{a},{b}}},key2=b", + "expected": {"key1": "{a},{b}", "key2": "b"} + }, + "Keyval Braces Mixed 3": { + "input": "key1={{{a}},{{b},{c}}},key2=b", + "expected": {"key1": "{{a}},{{b},{c}}", "key2": "b"} + }, + "Keyval Braces Mixed 3 Spaces": { + "input": "key1 = { { { a}},{{b},{c} } } ,key2=b", + "expected": {"key1": "{ { a}},{{b},{c} }", "key2": "b"} + }, + "Keyval Braces Mixed 4 Spaces": { + "input": "key1 = { { { { { { a}},{{b},{c} } } } } } ,key2=b", + "expected": {"key1": "{ { a}},{{b},{c} }", "key2": "b"} + }, + "Keyval Braces Equals Mixed 3": { + "input": "key1={{{a}}={{b},{c}}},key2=b", + "expected": {"key1": "{{a}}={{b},{c}}", "key2": "b"} + }, + "Keyval Error 1": { + "input": "key={{a}", + "expected": "Extra open brace or missing close brace" + }, + "Keyval Error 2": { + "input": "key={{a}{}", + "expected": "Extra open brace or missing close brace" + }, + "Keyval Error 3": { + "input": "key1=}, key2={", + "expected": "Extra open brace or missing close brace" + }, + "Keyval Unbalanced 1": { + "input": "key={a}}", + "expected": {"key": "a}"} + }, + "Keyval Unbalanced 2": { + "input": "key1={a}}, key2=}b", + "expected": {"key1": "a}", "key2": "}b"} + }, + "Keyval Unbalanced 3": { + "input": "key1=}, key2={}}", + "expected": {"key1": true, "key2": true} + } + } +} diff --git a/tests/src/other-test.js b/tests/src/other-test.js index 4563af2..bdbe8a1 100644 --- a/tests/src/other-test.js +++ b/tests/src/other-test.js @@ -1,7 +1,9 @@ import {ParserJsonTest} from './parser-test.js'; +import {JsonTest} from './test.js'; import {Configuration} from '../node_modules/mathjax-full/js/input/tex/Configuration.js'; import {CharacterMap} from '../node_modules/mathjax-full/js/input/tex/SymbolMap.js'; import ParseMethods from '../node_modules/mathjax-full/js/input/tex/ParseMethods.js'; +import ParseUtil from '../node_modules/mathjax-full/js/input/tex/ParseUtil.js'; export class ParserMultirelTest extends ParserJsonTest { @@ -40,3 +42,20 @@ export class ParserConfigMacrosTest extends ParserJsonTest { } +export class KeyvalTest extends JsonTest { + + runTest(name, input, expected) { + this.test( + name, + t => { + try { + let keyval = ParseUtil.keyvalOptions(input); + t.deepEqual(keyval, expected, name); + } catch (e) { + t.deepEqual(e.message, expected, name); + } + } + ); + } + +} diff --git a/tests/src/parser-test.js b/tests/src/parser-test.js index 385417a..0c3d4d6 100644 --- a/tests/src/parser-test.js +++ b/tests/src/parser-test.js @@ -20,71 +20,6 @@ let fs = require('fs'); RegisterHTMLHandler(chooseAdaptor()); -export class ParserTest extends Test { - - json = {}; - packages = ['ams', 'base']; - settings = {tags: 'none'}; - output = false; - - constructor() { - super(); - console.log(this.constructor.name); - console.log('\u001B\u005B\u0033\u0034\u006D' + - 'Running tests from ' + this.constructor.name + - '\u001B\u005B\u0033\u0037\u006D'); - this.json.name = this.constructor.name; - this.json.packages = this.packages; - this.json.settings = this.settings; - this.json.tests = {}; - } - - outTest(name, tex, expected) { - this.json.tests[name] = {input: tex, expected: expected}; - } - - printTime() { - super.printTime(); - if (this.output && !Object.keys(this.runningTests).length) { - console.log('Out: ' + this.json.name); - this.json.name = this.constructor.name; - this.json.packages = this.packages; - this.json.settings = this.settings; - fs.writeFileSync('json3/' + this.json.name + '.json', JSON.stringify(this.json, null, 2)); - } - } - - // Tests exclusively the timing of the Translate method. - runTest(name, tex, expected) { - this.outTest(name, tex,expected); - this.test( - name, - t => { - mathjax.handleRetriesFor(function() { - let options = {packages: this.packages}; - Object.assign(options, this.settings); - let html = mathjax.document('', { - InputJax: new TeX(options), OutputJax: new SVG() - }); - let root = html.convert(tex, {end: STATE.CONVERT}); - let jv = new JsonMmlVisitor(); - root.setTeXclass(null); - let actual = jv.visitTree(root); - t.deepEqual(actual, expected, name); - }.bind(this)).catch(err => { - console.log(err.message); - console.log(err.stack.replace(/\n.*\/system\.js:(.|\n)*/, '')); - }); - } - ); - } - - ignoreTest(name, tex, expected) { - } - -} - - export class ParserJsonTest extends JsonTest { packages = ['ams', 'base']; diff --git a/tests/src/test-factory.js b/tests/src/test-factory.js index 7be1cc1..bbacafd 100644 --- a/tests/src/test-factory.js +++ b/tests/src/test-factory.js @@ -1,11 +1,12 @@ import {ParserJsonTest} from './parser-test.js'; -import {ParserMultirelTest, ParserConfigMacrosTest} from './other-test.js'; +import {KeyvalTest, ParserMultirelTest, ParserConfigMacrosTest} from './other-test.js'; import {JsonTest} from './test.js'; let fs = require('fs'); export class TestFactory { static factory = { + 'keyvalTest': KeyvalTest, 'parserConfigMacros': ParserConfigMacrosTest, 'parserMultirel': ParserMultirelTest, 'parserTest': ParserJsonTest, diff --git a/tests/src/tex-keyval-tests.js b/tests/src/tex-keyval-tests.js deleted file mode 100644 index 3dc9af4..0000000 --- a/tests/src/tex-keyval-tests.js +++ /dev/null @@ -1,234 +0,0 @@ -import ParseUtil from '../node_modules/mathjax-full/js/input/tex/ParseUtil.js'; -import {Test} from './test.js'; - - -class KeyvalTest extends Test { - - runTest(name, options, expected) { - this.test( - name, - t => { - try { - let keyval = ParseUtil.keyvalOptions(options); - t.deepEqual(keyval, expected, name); - } catch (e) { - t.deepEqual(e.message, expected, name); - } - } - ); - } - -} - -let keyvalTest = new KeyvalTest(); - -keyvalTest.runTest( - 'Keyval Trival', 'key={{}}', - {key: true} -); - -keyvalTest.runTest( - 'Keyval Trivial 2', 'key1={{}},key2={{{{}}}}', - {key1: true, key2: true} -); - - -keyvalTest.runTest( - 'Keyval Trival3', 'key={{}{}}', - {key: '{}{}'} -); - -keyvalTest.runTest( - 'Keyval Trivial 4', 'key1= { { } },key2= {{ { { }} } }', - {key1: true, key2: true} -); - - -keyvalTest.runTest( - 'Keyval Single', 'key=a', - {key: 'a'} -); - -keyvalTest.runTest( - 'Keyval Double', 'key1=a,key2=b', - {key1: 'a', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Space', 'key1 = a , key2 = b', - {key1: 'a', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Single True', 'key1', - {key1: true} -); - -keyvalTest.runTest( - 'Keyval Double True', 'key1,key2', - {key1: true, key2: true} -); - -keyvalTest.runTest( - 'Keyval Mixed', 'key1=a,key2,key3=c', - {key1: 'a', key2: true, key3: 'c'} -); - -keyvalTest.runTest( - 'Keyval Empty Comma Begin', ',key1=a,key2,key3=c', - {key1: 'a', key2: true, key3: 'c'} -); - -keyvalTest.runTest( - 'Keyval Empty Comma Mid', 'key1=a,,key2,key3=c', - {key1: 'a', key2: true, key3: 'c'} -); - -keyvalTest.runTest( - 'Keyval Empty Comma End', 'key1=a,key2,key3=c,', - {key1: 'a', key2: true, key3: 'c'} -); - -keyvalTest.runTest( - 'Keyval Empty Comma Multi', ',,key1=a,,,,key2,key3=c,,', - {key1: 'a', key2: true, key3: 'c'} -); - -keyvalTest.runTest( - 'Keyval Braces', 'key1={a},key2=b', - {key1: 'a', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces 2', 'key1={{a}},key2=b', - {key1: 'a', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces 3', 'key1={{{a}}},key2=b', - {key1: 'a', key2: 'b'} -); - - -keyvalTest.runTest( - 'Keyval Braces Comma', 'key1={a,b,c},key2=b', - {key1: 'a,b,c', key2: 'b'} -); - - -keyvalTest.runTest( - 'Keyval Braces Equal', 'key1={a=c},key2=b', - {key1: 'a=c', key2: 'b'} -); - - -keyvalTest.runTest( - 'Keyval Braces Comma Equal', 'key1={a=c,b},key2=b', - {key1: 'a=c,b', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces Simple 1', 'key1={{a}}', - {key1: 'a'} -); - -keyvalTest.runTest( - 'Keyval Braces Simple 2', 'key1={{a{b}}}', - {key1: 'a{b}'} -); - -keyvalTest.runTest( - 'Keyval Braces Simple 3', 'key1={{a={b}}}', - {key1: 'a={b}'} -); - -keyvalTest.runTest( - 'Keyval Braces Prefix', 'key1={{}a}', - {key1: '{}a'} -); - -keyvalTest.runTest( - 'Keyval Braces Prefix 2', 'key1={{{}}a}', - {key1: '{{}}a'} -); - -keyvalTest.runTest( - 'Keyval Braces Prefix 3', 'key1={{}{}a}', - {key1: '{}{}a'} -); - -keyvalTest.runTest( - 'Keyval Braces Prefix 4', 'key1={{{}{}a}}', - {key1: '{}{}a'} -); - -keyvalTest.runTest( - 'Keyval Braces Prefix 5', 'key1={{}{a}}', - {key1: '{}{a}'} -); - -keyvalTest.runTest( - 'Keyval Braces Prefix 6', 'key1={{{}}{a}}', - {key1: '{{}}{a}'} -); - -keyvalTest.runTest( - 'Keyval Braces Mixed 1', 'key1={{a},{b}},key2=b', - {key1: '{a},{b}', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces Mixed 2', 'key1={{{a},{b}}},key2=b', - {key1: '{a},{b}', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces Mixed 3', 'key1={{{a}},{{b},{c}}},key2=b', - {key1: '{{a}},{{b},{c}}', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces Mixed 3 Spaces', 'key1 = { { { a}},{{b},{c} } } ,key2=b', - {key1: '{ { a}},{{b},{c} }', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces Mixed 4 Spaces', 'key1 = { { { { { { a}},{{b},{c} } } } } } ,key2=b', - {key1: '{ { a}},{{b},{c} }', key2: 'b'} -); - -keyvalTest.runTest( - 'Keyval Braces Equals Mixed 3', 'key1={{{a}}={{b},{c}}},key2=b', - {key1: '{{a}}={{b},{c}}', key2: 'b'} -); - - -keyvalTest.runTest( - 'Keyval Error 1', 'key={{a}', - 'Extra open brace or missing close brace' -); - -keyvalTest.runTest( - 'Keyval Error 2', 'key={{a}{}', - 'Extra open brace or missing close brace' -); - -keyvalTest.runTest( - 'Keyval Error 3', 'key1=}, key2={', - 'Extra open brace or missing close brace' -); - -keyvalTest.runTest( - 'Keyval Unbalanced 1', 'key={a}}', - {key: 'a}'} -); - -keyvalTest.runTest( - 'Keyval Unbalanced 2', 'key1={a}}, key2=}b', - {key1: 'a}', key2: '}b'} -); - -keyvalTest.runTest( - 'Keyval Unbalanced 3', 'key1=}, key2={}}', - {key1: true, key2: true} -); diff --git a/tests/tests.sh b/tests/tests.sh index 1160f1b..ad31909 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -5,7 +5,8 @@ JSON=$DIR/json if [ $# -eq 0 ]; then - $NODE $DIR/src/tex-keyval-tests.js + $NODE src/run-test.js $JSON/KeyvalTest.json + ## $NODE $DIR/src/tex-keyval-tests.js $NODE src/run-test.js $JSON/ParserActionTest.json ## Reordered From 32cdad42259f3ccf27167f7e9e16606a4584343d Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 8 Oct 2020 17:41:17 +0100 Subject: [PATCH 2/3] Class refactoring and cleanup. --- tests/json/ParserBussproofsRegInfTest.json | 4 +- tests/json/ParserBussproofsRegProofsTest.json | 4 +- tests/src/other-test.js | 40 -------- tests/src/parser-test.js | 92 +++++++++++++++++-- tests/src/test-factory.js | 11 ++- 5 files changed, 93 insertions(+), 58 deletions(-) diff --git a/tests/json/ParserBussproofsRegInfTest.json b/tests/json/ParserBussproofsRegInfTest.json index 04aff1f..736985e 100644 --- a/tests/json/ParserBussproofsRegInfTest.json +++ b/tests/json/ParserBussproofsRegInfTest.json @@ -1,6 +1,6 @@ { "name": "ParserBussproofsRegInfTest", - "factory": "parserTest", + "factory": "parserOutputTest", "packages": [ "base", "ams", @@ -8067,4 +8067,4 @@ } } } -} \ No newline at end of file +} diff --git a/tests/json/ParserBussproofsRegProofsTest.json b/tests/json/ParserBussproofsRegProofsTest.json index a2da832..8684806 100644 --- a/tests/json/ParserBussproofsRegProofsTest.json +++ b/tests/json/ParserBussproofsRegProofsTest.json @@ -1,6 +1,6 @@ { "name": "ParserBussproofsRegProofsTest", - "factory": "parserTest", + "factory": "parserOutputTest", "packages": [ "base", "ams", @@ -29032,4 +29032,4 @@ } } } -} \ No newline at end of file +} diff --git a/tests/src/other-test.js b/tests/src/other-test.js index bdbe8a1..5a0f66a 100644 --- a/tests/src/other-test.js +++ b/tests/src/other-test.js @@ -1,47 +1,7 @@ -import {ParserJsonTest} from './parser-test.js'; import {JsonTest} from './test.js'; -import {Configuration} from '../node_modules/mathjax-full/js/input/tex/Configuration.js'; -import {CharacterMap} from '../node_modules/mathjax-full/js/input/tex/SymbolMap.js'; -import ParseMethods from '../node_modules/mathjax-full/js/input/tex/ParseMethods.js'; import ParseUtil from '../node_modules/mathjax-full/js/input/tex/ParseUtil.js'; -export class ParserMultirelTest extends ParserJsonTest { - - constructor(json) { - // Just some things bogus attributes for testing. - new CharacterMap('shadow', ParseMethods.mathchar0mo, { - sim: ['\u223C', {something: 'nothing'}], - simeq: ['\u2243', {something: 'nothing'}], - asymp: ['\u224D', {something: 'else'}], - cong: ['\u224D', {anything: 'nothing'}], - lesssim: ['\u2272', {lspace: '1pt'}], - gtrsim: ['\u2278', {rspace: '1pt'}] - }); - Configuration.create('multirel-test', {handler: {macro: ['shadow']}, priority: 4}); - super(json); - this.packages = ['base', 'ams', 'multirel-test']; - } - -} - - -export class ParserConfigMacrosTest extends ParserJsonTest { - - constructor(json) { - super(json); - this.packages = ['base', 'configmacros']; - Object.assign(this.settings, {macros:{}}); - } - - runTest(name, input, expected, {macro, control}) { - Object.assign(this.settings.macros, macro); - super.runTest(name, control, expected); - super.runTest(name, input, expected); - } - -} - export class KeyvalTest extends JsonTest { runTest(name, input, expected) { diff --git a/tests/src/parser-test.js b/tests/src/parser-test.js index 0c3d4d6..a791533 100644 --- a/tests/src/parser-test.js +++ b/tests/src/parser-test.js @@ -1,7 +1,6 @@ import {mathjax} from '../node_modules/mathjax-full/js/mathjax.js'; import {TeX} from '../node_modules/mathjax-full/js/input/tex.js'; -import {SVG} from '../node_modules/mathjax-full/js/output/svg.js'; import {RegisterHTMLHandler} from "../node_modules/mathjax-full/js/handlers/html.js"; import {chooseAdaptor} from "../node_modules/mathjax-full/js/adaptors/chooseAdaptor.js"; import {JsonMmlVisitor} from '../node_modules/mathjax-full/js/core/MmlTree/JsonMmlVisitor.js'; @@ -9,23 +8,27 @@ import {STATE} from '../node_modules/mathjax-full/js/core/MathItem.js'; import {TagsFactory} from '../node_modules/mathjax-full/js/input/tex/Tags.js'; import {MapHandler} from "../node_modules/mathjax-full/js/input/tex/MapHandler.js"; +import {AllPackages} from '../node_modules/mathjax-full/js/input/tex/AllPackages.js'; import {JsonTest, Test} from './test.js'; -import {AllPackages} from '../node_modules/mathjax-full/js/input/tex/AllPackages.js'; -import '../node_modules/mathjax-full/js/input/tex/base/BaseConfiguration.js'; -import '../node_modules/mathjax-full/js/input/tex/ams/AmsConfiguration.js'; - let fs = require('fs'); RegisterHTMLHandler(chooseAdaptor()); + +/** + * Parser tests from JSON input files. + */ export class ParserJsonTest extends JsonTest { packages = ['ams', 'base']; settings = {tags: 'none'}; name = ''; + /** + * @override + */ constructor(json) { super(json); this.packages = this.json['packages'] || this.packages; @@ -46,7 +49,15 @@ export class ParserJsonTest extends JsonTest { } } + document(options) { + return mathjax.document('', { + InputJax: new TeX(options) + }); + } + /** + * @override + */ runTest(name, tex, expected, rest) { this.test( name, @@ -54,10 +65,7 @@ export class ParserJsonTest extends JsonTest { mathjax.handleRetriesFor(function() { let options = {packages: this.packages}; Object.assign(options, this.settings); - let html = mathjax.document('', { - InputJax: new TeX(options), OutputJax: new SVG() - }); - let root = html.convert(tex, {end: STATE.CONVERT}); + let root = this.document(options).convert(tex, {end: STATE.CONVERT}); let jv = new JsonMmlVisitor(); root.setTeXclass(null); let actual = jv.visitTree(root); @@ -71,3 +79,69 @@ export class ParserJsonTest extends JsonTest { } } + + +import {SVG} from '../node_modules/mathjax-full/js/output/svg.js'; + +/** + * Parser tests for packages that require an output jax. + */ +export class ParserOutputTest extends ParserJsonTest { + + /** + * @override + */ + document(options) { + return mathjax.document('', { + InputJax: new TeX(options), OutputJax: new SVG() + }); + } + +} + +import {Configuration} from '../node_modules/mathjax-full/js/input/tex/Configuration.js'; +import {CharacterMap} from '../node_modules/mathjax-full/js/input/tex/SymbolMap.js'; +import ParseMethods from '../node_modules/mathjax-full/js/input/tex/ParseMethods.js'; + +/** + * Parser tests for multi relations method. + */ +export class ParserMultirelTest extends ParserJsonTest { + + constructor(json) { + // Just some things bogus attributes for testing. + new CharacterMap('shadow', ParseMethods.mathchar0mo, { + sim: ['\u223C', {something: 'nothing'}], + simeq: ['\u2243', {something: 'nothing'}], + asymp: ['\u224D', {something: 'else'}], + cong: ['\u224D', {anything: 'nothing'}], + lesssim: ['\u2272', {lspace: '1pt'}], + gtrsim: ['\u2278', {rspace: '1pt'}] + }); + Configuration.create('multirel-test', {handler: {macro: ['shadow']}, priority: 4}); + super(json); + this.packages = ['base', 'ams', 'multirel-test']; + } + +} + + +/** + * Parser tests for macro configurations. + */ +export class ParserConfigMacrosTest extends ParserJsonTest { + + constructor(json) { + super(json); + this.packages = ['base', 'configmacros']; + Object.assign(this.settings, {macros:{}}); + } + + runTest(name, input, expected, {macro, control}) { + Object.assign(this.settings.macros, macro); + super.runTest(name, control, expected); + super.runTest(name, input, expected); + } + +} + diff --git a/tests/src/test-factory.js b/tests/src/test-factory.js index bbacafd..bf7b6b5 100644 --- a/tests/src/test-factory.js +++ b/tests/src/test-factory.js @@ -1,5 +1,5 @@ -import {ParserJsonTest} from './parser-test.js'; -import {KeyvalTest, ParserMultirelTest, ParserConfigMacrosTest} from './other-test.js'; +import * as pt from './parser-test.js'; +import {KeyvalTest} from './other-test.js'; import {JsonTest} from './test.js'; let fs = require('fs'); @@ -7,9 +7,10 @@ export class TestFactory { static factory = { 'keyvalTest': KeyvalTest, - 'parserConfigMacros': ParserConfigMacrosTest, - 'parserMultirel': ParserMultirelTest, - 'parserTest': ParserJsonTest, + 'parserConfigMacros': pt.ParserConfigMacrosTest, + 'parserMultirel': pt.ParserMultirelTest, + 'parserOutput': pt.ParserOutputTest, + 'parserTest': pt.ParserJsonTest, 'test': JsonTest } From 49808cd3055d6c0f962c85aacbcf32e1e1affc04 Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 8 Oct 2020 17:44:58 +0100 Subject: [PATCH 3/3] Adds copyright and file overview. --- tests/src/other-test.js | 24 ++++++++++++++++++++++++ tests/src/parser-test.js | 24 ++++++++++++++++++++++++ tests/src/run-test.js | 24 ++++++++++++++++++++++++ tests/src/test-factory.js | 24 ++++++++++++++++++++++++ tests/src/test.js | 24 ++++++++++++++++++++++++ 5 files changed, 120 insertions(+) diff --git a/tests/src/other-test.js b/tests/src/other-test.js index 5a0f66a..ce9d129 100644 --- a/tests/src/other-test.js +++ b/tests/src/other-test.js @@ -1,3 +1,27 @@ +/************************************************************* + * + * Copyright (c) 2020 The MathJax Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @fileoverview Various test classes that use JSON input. + * + * @author v.sorge@mathjax.org (Volker Sorge) + */ + import {JsonTest} from './test.js'; import ParseUtil from '../node_modules/mathjax-full/js/input/tex/ParseUtil.js'; diff --git a/tests/src/parser-test.js b/tests/src/parser-test.js index a791533..c992eb0 100644 --- a/tests/src/parser-test.js +++ b/tests/src/parser-test.js @@ -1,3 +1,27 @@ +/************************************************************* + * + * Copyright (c) 2020 The MathJax Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @fileoverview All classes that test the TeX parser. + * + * @author v.sorge@mathjax.org (Volker Sorge) + */ + import {mathjax} from '../node_modules/mathjax-full/js/mathjax.js'; import {TeX} from '../node_modules/mathjax-full/js/input/tex.js'; diff --git a/tests/src/run-test.js b/tests/src/run-test.js index 13a712e..f30c787 100644 --- a/tests/src/run-test.js +++ b/tests/src/run-test.js @@ -1,3 +1,27 @@ +/************************************************************* + * + * Copyright (c) 2020 The MathJax Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @fileoverview The current test runner. + * + * @author v.sorge@mathjax.org (Volker Sorge) + */ + import {TestFactory} from './test-factory.js'; let process = require('process'); diff --git a/tests/src/test-factory.js b/tests/src/test-factory.js index bf7b6b5..5668a4d 100644 --- a/tests/src/test-factory.js +++ b/tests/src/test-factory.js @@ -1,3 +1,27 @@ +/************************************************************* + * + * Copyright (c) 2020 The MathJax Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @fileoverview Factory for tests based on JSON input files. + * + * @author v.sorge@mathjax.org (Volker Sorge) + */ + import * as pt from './parser-test.js'; import {KeyvalTest} from './other-test.js'; import {JsonTest} from './test.js'; diff --git a/tests/src/test.js b/tests/src/test.js index 2417d2d..eab10c5 100644 --- a/tests/src/test.js +++ b/tests/src/test.js @@ -1,3 +1,27 @@ +/************************************************************* + * + * Copyright (c) 2020 The MathJax Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @fileoverview Basic test classes. + * + * @author v.sorge@mathjax.org (Volker Sorge) + */ + /* globals System: true */ let test = require('tape');