Jasmine: Convert |reportMissingRules| compiler pass tests
parent
ef25ec08c2
commit
2889ca72fc
@ -0,0 +1,82 @@
|
|||||||
|
describe("compiler pass |reportMissingRules|", function() {
|
||||||
|
var pass = PEG.compiler.passes.reportMissingRules;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
this.addMatchers({
|
||||||
|
toReportMissingRuleIn: function(grammar) {
|
||||||
|
var ast = PEG.parser.parse(grammar);
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.actual(ast);
|
||||||
|
|
||||||
|
this.message = function() {
|
||||||
|
return "Expected the pass to report a missing rule for grammar "
|
||||||
|
+ jasmine.pp(grammar) + ", "
|
||||||
|
+ "but it didn't.";
|
||||||
|
};
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
if (this.isNot) {
|
||||||
|
this.message = function() {
|
||||||
|
return "Expected the pass not to report a missing rule for grammar "
|
||||||
|
+ jasmine.pp(grammar) + ", "
|
||||||
|
+ "but it did.";
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.message = function() {
|
||||||
|
return "Expected the pass to report a missing rule for grammar "
|
||||||
|
+ jasmine.pp(grammar) + ", "
|
||||||
|
+ "but it reported an error with message "
|
||||||
|
+ jasmine.pp(e.message) + ".";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.message === 'Referenced rule "missing" does not exist.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a rule", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a choice", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing / "a" / "b"');
|
||||||
|
expect(pass).toReportMissingRuleIn('start = "a" / "b" / missing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a sequence", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing "a" "b"');
|
||||||
|
expect(pass).toReportMissingRuleIn('start = "a" "b" missing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a labeled", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = label:missing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a simple and", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = &missing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a simple not", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = &missing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from an optional", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing?');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a zero or more", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing*');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from a one or more", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing+');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports missing rule referenced from an action", function() {
|
||||||
|
expect(pass).toReportMissingRuleIn('start = missing { }');
|
||||||
|
});
|
||||||
|
});
|
@ -1,37 +0,0 @@
|
|||||||
(function() {
|
|
||||||
|
|
||||||
module("PEG.compiler.passes.reportMissingRules");
|
|
||||||
|
|
||||||
test("reports missing referenced rules", function() {
|
|
||||||
function testGrammar(grammar) {
|
|
||||||
raises(
|
|
||||||
function() {
|
|
||||||
var ast = PEG.parser.parse(grammar);
|
|
||||||
PEG.compiler.passes.reportMissingRules(ast);
|
|
||||||
},
|
|
||||||
function(e) {
|
|
||||||
return e instanceof PEG.GrammarError
|
|
||||||
&& e.message === "Referenced rule \"missing\" does not exist.";
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
var grammars = [
|
|
||||||
'start = missing',
|
|
||||||
'start = missing / "a" / "b"',
|
|
||||||
'start = "a" / "b" / missing',
|
|
||||||
'start = missing "a" "b"',
|
|
||||||
'start = "a" "b" missing',
|
|
||||||
'start = label:missing',
|
|
||||||
'start = &missing',
|
|
||||||
'start = !missing',
|
|
||||||
'start = missing?',
|
|
||||||
'start = missing*',
|
|
||||||
'start = missing+',
|
|
||||||
'start = missing { }'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var i = 0; i < grammars.length; i++) { testGrammar(grammars[i]); }
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
|
Loading…
Reference in New Issue