Jasmine: Convert tests of parser's "string" rule

redux
David Majda 13 years ago
parent fa65018b15
commit 573db92583

@ -1,7 +1,7 @@
describe("PEG.js grammar parser", function() {
var trivialGrammar;
function oneRuleGrammar(expression) {
function oneRuleGrammar(displayName, expression) {
return {
type: "grammar",
initializer: null,
@ -9,7 +9,7 @@ describe("PEG.js grammar parser", function() {
{
type: "rule",
name: "start",
displayName: null,
displayName: displayName,
expression: expression
}
],
@ -18,14 +18,18 @@ describe("PEG.js grammar parser", function() {
}
function literalGrammar(value) {
return oneRuleGrammar({ type: "literal", value: value, ignoreCase: false });
return oneRuleGrammar(null, {
type: "literal",
value: value,
ignoreCase: false
});
}
function classGrammar(parts, rawText) {
var inverted = arguments.length > 2 ? arguments[2] : false,
ignoreCase = arguments.length > 3 ? arguments[3] : false;
return oneRuleGrammar({
return oneRuleGrammar(null, {
type: "class",
inverted: inverted,
ignoreCase: ignoreCase,
@ -115,6 +119,20 @@ describe("PEG.js grammar parser", function() {
});
});
/* Canonical string is "\"abcd\"". */
it("parses string", function() {
var grammar = oneRuleGrammar("abcd", {
type: "literal",
value: "abcd",
ignoreCase: false
});
expect('start "abcd" = "abcd"' ).toParseAs(grammar);
expect('start \'abcd\' = "abcd"').toParseAs(grammar);
expect('start "abcd"\n= "abcd"').toParseAs(grammar);
});
/* Canonical doubleQuotedString is "\"abcd\"". */
it("parses doubleQuotedString", function() {
expect('start = ""' ).toParseAs(literalGrammar(""));

@ -347,12 +347,4 @@ test("parses literal", function() {
parserParses('start = "abcd"\n', literalGrammar("abcd"));
});
/* Canonical string is "\"abcd\"". */
test("parses string", function() {
parserParses('start "abcd" = "abcd"', namedRuleGrammar);
parserParses('start \'abcd\' = "abcd"', namedRuleGrammar);
parserParses('start "abcd"\n= "abcd"', namedRuleGrammar);
});
})();

Loading…
Cancel
Save