commit bcd6e8687f114169a9e3463ea07ff6008d3f76e6
parent 975234e8131a5639a738a2d761a44741b8127ad5
Author: Emily Eisenberg <emily@khanacademy.org>
Date: Tue, 16 Jul 2013 17:46:58 -0700
Fix the failing frac test
Summary: Also add some more frac tests
Auditors: alpert
Diffstat:
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/test/katex-tests.js b/test/katex-tests.js
@@ -288,7 +288,7 @@ describe("A function parser", function() {
it("should parse 2 argument functions", function() {
expect(function() {
- parseTree("\\dfrac 1 2");
+ parseTree("\\frac 1 2");
}).not.toThrow();
});
@@ -300,11 +300,11 @@ describe("A function parser", function() {
it("should not parse 2 argument functions with 0 or 1 arguments", function() {
expect(function() {
- parseTree("\\dfrac");
+ parseTree("\\frac");
}).toThrow();
expect(function() {
- parseTree("\\dfrac 1");
+ parseTree("\\frac 1");
}).toThrow();
});
@@ -316,7 +316,7 @@ describe("A function parser", function() {
it("should parse a function with a number right after it", function() {
expect(function() {
- parseTree("\\dfrac12");
+ parseTree("\\frac12");
}).not.toThrow();
});
@@ -327,8 +327,10 @@ describe("A function parser", function() {
});
});
-describe("A dfrac parser", function() {
- var expression = "\\dfrac{x}{y}";
+describe("A frac parser", function() {
+ var expression = "\\frac{x}{y}";
+ var dfracExpression = "\\dfrac{x}{y}";
+ var tfracExpression = "\\tfrac{x}{y}";
it("should not fail", function() {
expect(function() {
@@ -336,11 +338,35 @@ describe("A dfrac parser", function() {
}).not.toThrow();
});
- it("should produce a dfrac", function() {
+ it("should produce a frac", function() {
var parse = parseTree(expression)[0];
- expect(parse.type).toMatch("dfrac");
+ expect(parse.type).toMatch("frac");
expect(parse.value.numer).toBeDefined();
expect(parse.value.denom).toBeDefined();
});
+
+ it("should also parse dfrac and tfrac", function() {
+ expect(function() {
+ parseTree(dfracExpression);
+ }).not.toThrow();
+
+ expect(function() {
+ parseTree(tfracExpression);
+ }).not.toThrow();
+ });
+
+ it("should parse dfrac and tfrac as fracs", function() {
+ var dfracParse = parseTree(dfracExpression)[0];
+
+ expect(dfracParse.type).toMatch("frac");
+ expect(dfracParse.value.numer).toBeDefined();
+ expect(dfracParse.value.denom).toBeDefined();
+
+ var tfracParse = parseTree(tfracExpression)[0];
+
+ expect(tfracParse.type).toMatch("frac");
+ expect(tfracParse.value.numer).toBeDefined();
+ expect(tfracParse.value.denom).toBeDefined();
+ });
});