Make supsub work with empty nucleus

Auditors: emily
This commit is contained in:
Ben Alpert 2013-08-17 16:07:22 -07:00
parent f58f582aa5
commit 944b55a6b0
2 changed files with 25 additions and 1 deletions

View File

@ -52,7 +52,10 @@ var groupToType = {
};
var getTypeOfGroup = function(group) {
if (group.type === "supsub") {
if (group == null) {
// Like when typesetting $^3$
return groupToType.ord;
} else if (group.type === "supsub") {
return getTypeOfGroup(group.value.base);
} else if (group.type === "llap" || group.type === "rlap") {
return getTypeOfGroup(group.value);

View File

@ -1,3 +1,4 @@
var buildTree = require("../buildTree");
var parseTree = require("../parseTree");
describe("A parser", function() {
@ -286,6 +287,26 @@ describe("A subscript and superscript parser", function() {
});
});
describe("A subscript and superscript tree-builder", function() {
it("should not fail when there is no nucleus", function() {
expect(function() {
buildTree(parseTree("^3"));
}).not.toThrow();
expect(function() {
buildTree(parseTree("_2"));
}).not.toThrow();
expect(function() {
buildTree(parseTree("^3_2"));
}).not.toThrow();
expect(function() {
buildTree(parseTree("_2^3"));
}).not.toThrow();
});
});
describe("A group parser", function() {
it("should not fail", function() {
expect(function() {