Jasmine: Convert tests of parser's "whitespace" rule
This commit is contained in:
parent
c27b96051a
commit
a46b9c197b
|
@ -1,6 +1,8 @@
|
||||||
describe("PEG.js grammar parser", function() {
|
describe("PEG.js grammar parser", function() {
|
||||||
it("works", function() {
|
var trivialGrammar;
|
||||||
expect(PEG.parser.parse('start = "a"')).toEqual({
|
|
||||||
|
beforeEach(function() {
|
||||||
|
trivialGrammar = {
|
||||||
type: "grammar",
|
type: "grammar",
|
||||||
initializer: null,
|
initializer: null,
|
||||||
rules: [
|
rules: [
|
||||||
|
@ -8,10 +10,64 @@ describe("PEG.js grammar parser", function() {
|
||||||
type: "rule",
|
type: "rule",
|
||||||
name: "start",
|
name: "start",
|
||||||
displayName: null,
|
displayName: null,
|
||||||
expression: { type: "literal", value: "a", ignoreCase: false }
|
expression: { type: "literal", value: "abcd", ignoreCase: false }
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
startRule: "start"
|
startRule: "start"
|
||||||
|
};
|
||||||
|
|
||||||
|
this.addMatchers({
|
||||||
|
toParseAs: function(expected) {
|
||||||
|
var result;
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = PEG.parser.parse(this.actual);
|
||||||
|
|
||||||
|
this.message = function() {
|
||||||
|
return "Expected " + jasmine.pp(this.actual) + " "
|
||||||
|
+ (this.isNot ? "not " : "")
|
||||||
|
+ "to parse as " + jasmine.pp(expected) + ", "
|
||||||
|
+ "but it parsed as " + jasmine.pp(result) + ".";
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.env.equals_(result, expected);
|
||||||
|
} catch (e) {
|
||||||
|
this.message = function() {
|
||||||
|
return "Expected " + jasmine.pp(this.actual) + " "
|
||||||
|
+ "to parse as " + jasmine.pp(expected) + ", "
|
||||||
|
+ "but it failed to parse with message "
|
||||||
|
+ jasmine.pp(e.message) + ".";
|
||||||
|
};
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Canonical whitespace is " ". */
|
||||||
|
it("parses whitespace", function() {
|
||||||
|
expect('start =\t"abcd"' ).toParseAs(trivialGrammar);
|
||||||
|
expect('start =\x0B"abcd"' ).toParseAs(trivialGrammar); // no "\v" in IE
|
||||||
|
expect('start =\f"abcd"' ).toParseAs(trivialGrammar);
|
||||||
|
expect('start = "abcd"' ).toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u00A0"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\uFEFF"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u1680"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u180E"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2000"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2001"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2002"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2003"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2004"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2005"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2006"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2007"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2008"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u2009"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u200A"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u202F"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u205F"abcd"').toParseAs(trivialGrammar);
|
||||||
|
expect('start =\u3000"abcd"').toParseAs(trivialGrammar);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -580,31 +580,4 @@ test("parses eolChar", function() {
|
||||||
parserParses('start =\u2029"abcd"', simpleGrammar);
|
parserParses('start =\u2029"abcd"', simpleGrammar);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Canonical whitespace is " ". */
|
|
||||||
test("parses whitespace", function() {
|
|
||||||
parserParses('start =\t"abcd"', simpleGrammar);
|
|
||||||
/* IE does not recognize "\v". */
|
|
||||||
parserParses('start =\x0B"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\f"abcd"', simpleGrammar);
|
|
||||||
parserParses('start = "abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u00A0"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\uFEFF"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u1680"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u180E"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2000"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2001"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2002"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2003"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2004"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2005"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2006"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2007"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2008"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u2009"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u200A"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u202F"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u205F"abcd"', simpleGrammar);
|
|
||||||
parserParses('start =\u3000"abcd"', simpleGrammar);
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue