Add support for \left and \right

Summary:
Added stacked delimiter support for more delimiters. Split out delimiter
functions into its own file, and split out some tree building functions into a
common file. Supports the empty `.` delimiter with \left and \right, and doesn't
try to produce huge /, \backslash, <, or > delimiters. Depends on D7844

Test input:

\left( \left) \left[ \left\lbrack \left] \left\rbrack \left\{ \left\lbrace
\left\} \left\rbrace \left\lfloor \left\rfloor \left\lceil \left\rceil
\left\langle \left\rangle \left/ \left\backslash \left| \left\vert \left\|
\left\Vert \left\uparrow \left\Uparrow \left\downarrow \left\Downarrow
\left\updownarrow \left\Updownarrow {x^{x^{x^{x^{x^{x^{x^{x^{x^{x^x}}}}}}}}}}
\right.\right.\right.\right.\right.\right.\right.\right.\right.\right.
\right.\right.\right.\right.\right.\right.\right.\right.\right.\right.
\right.\right.\right.\right.\right.\right.\right.\right.

Test Plan:
 - Run the test input, see that it works
 - Run the tests, see that they work
 - Look at huxley screenshots (not here yet :( ) and make sure they look good

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D11602
This commit is contained in:
Emily Eisenberg
2014-09-04 21:58:43 -07:00
parent 513ae30fe1
commit c3f758c319
22 changed files with 837 additions and 317 deletions

View File

@@ -739,3 +739,62 @@ describe("A rule parser", function() {
expect(hardNumberParse.value.height.number).toBeCloseTo(2.45);
});
});
describe("A left/right parser", function() {
var normalLeftRight = "\\left( \\dfrac{x}{y} \\right)";
var emptyRight = "\\left( \\dfrac{x}{y} \\right.";
it("should not fail", function() {
expect(function() {
parseTree(normalLeftRight);
}).not.toThrow();
});
it("should produce a leftright", function() {
var parse = parseTree(normalLeftRight)[0];
expect(parse.type).toMatch("leftright");
expect(parse.value.left).toMatch("\\(");
expect(parse.value.right).toMatch("\\)");
});
it("should error when it is mismatched", function() {
var unmatchedLeft = "\\left( \\dfrac{x}{y}";
var unmatchedRight = "\\dfrac{x}{y} \\right)";
expect(function() {
parseTree(unmatchedLeft);
}).toThrow();
expect(function() {
parseTree(unmatchedRight);
}).toThrow();
});
it("should error when braces are mismatched", function() {
var unmatched = "{ \\left( \\dfrac{x}{y} } \\right)";
expect(function() {
parseTree(unmatched);
}).toThrow();
});
it("should error when non-delimiters are provided", function() {
var nonDelimiter = "\\left$ \\dfrac{x}{y} \\right)";
expect(function() {
parseTree(nonDelimiter);
}).toThrow();
});
it("should parse the empty '.' delimiter", function() {
expect(function() {
parseTree(emptyRight);
}).not.toThrow();
});
it("should parse the '.' delimiter with normal sizes", function() {
var normalEmpty = "\\Bigl .";
expect(function() {
parseTree(normalEmpty);
}).not.toThrow();
});
});