Skip to content

Commit

Permalink
Merge pull request #39 from mathjax/rewrite_tests
Browse files Browse the repository at this point in the history
Rewrite tests
  • Loading branch information
zorkow authored Oct 9, 2020
2 parents 8db821d + 49808cd commit 237b9f9
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 356 deletions.
170 changes: 170 additions & 0 deletions tests/json/KeyvalTest.json
Original file line number Diff line number Diff line change
@@ -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}
}
}
}
4 changes: 2 additions & 2 deletions tests/json/ParserBussproofsRegInfTest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ParserBussproofsRegInfTest",
"factory": "parserTest",
"factory": "parserOutputTest",
"packages": [
"base",
"ams",
Expand Down Expand Up @@ -8067,4 +8067,4 @@
}
}
}
}
}
4 changes: 2 additions & 2 deletions tests/json/ParserBussproofsRegProofsTest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ParserBussproofsRegProofsTest",
"factory": "parserTest",
"factory": "parserOutputTest",
"packages": [
"base",
"ams",
Expand Down Expand Up @@ -29032,4 +29032,4 @@
}
}
}
}
}
81 changes: 42 additions & 39 deletions tests/src/other-test.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
import {ParserJsonTest} from './parser-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';


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'];
/*************************************************************
*
* 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 [email protected] (Volker Sorge)
*/

import {JsonTest} from './test.js';
import ParseUtil from '../node_modules/mathjax-full/js/input/tex/ParseUtil.js';


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);
}
}
);
}

}


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);
}

}

Loading

0 comments on commit 237b9f9

Please sign in to comment.