allow sizing commands inside optional groups (#885)

* allow sizing commands inside optional groups

* allow color, old font, and style commands inside optional groups
This commit is contained in:
Kevin Barabash
2017-10-03 11:30:59 -06:00
committed by GitHub
parent 1c1b3c81b6
commit 71e0b35b27
7 changed files with 235 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
/* global expect: false */
/* global it: false */
/* global describe: false */
import stringify from 'json-stable-stringify';
import buildMathML from "../src/buildMathML";
import buildTree from "../src/buildTree";
@@ -13,6 +14,27 @@ import Options from "../src/Options";
import Settings from "../src/Settings";
import Style from "../src/Style";
const typeFirstCompare = (a, b) => {
if (a.key === 'type') {
return -1;
} else if (b.key === 'type') {
return 1;
} else {
return a.key < b.key ? -1 : 1;
}
};
const serializer = {
print(val) {
return stringify(val, {cmp: typeFirstCompare, space: ' '});
},
test() {
return true;
},
};
expect.addSnapshotSerializer(serializer);
const defaultSettings = new Settings({});
const defaultOptions = new Options({
style: Style.TEXT,
@@ -520,6 +542,28 @@ describe("An implicit group parser", function() {
expect(sizing.type).toEqual("sizing");
expect(sizing.value.value.length).toBe(1);
});
describe("within optional groups", () => {
it("should work with sizing commands: \\sqrt[\\small 3]{x}", () => {
const tree = stripPositions(getParsed("\\sqrt[\\small 3]{x}"));
expect(tree).toMatchSnapshot();
});
it("should work with \\color: \\sqrt[\\color{red} 3]{x}", () => {
const tree = stripPositions(getParsed("\\sqrt[\\color{red} 3]{x}"));
expect(tree).toMatchSnapshot();
});
it("should work style commands \\sqrt[\\textstyle 3]{x}", () => {
const tree = stripPositions(getParsed("\\sqrt[\\textstyle 3]{x}"));
expect(tree).toMatchSnapshot();
});
it("should work wwith old font functions: \\sqrt[\\tt 3]{x}", () => {
const tree = stripPositions(getParsed("\\sqrt[\\tt 3]{x}"));
expect(tree).toMatchSnapshot();
});
});
});
describe("A function parser", function() {