Jasmine: Convert sequence matching tests

redux
David Majda 12 years ago
parent ae8a89c9e4
commit 1b0789fbae

@ -91,6 +91,28 @@ describe("generated parser", function() {
});
});
describe("sequence matching", function() {
varyAll(function(options) {
it("matches empty sequence correctly", function() {
var parser = PEG.buildParser('start = ', options);
expect(parser).toParse("", []);
});
it("matches non-empty sequence correctly", function() {
var parser = PEG.buildParser('start = "a" "b" "c"', options);
expect(parser).toParse("abc", ["a", "b", "c"]);
});
it("does not advance position on failure", function() {
var parser = PEG.buildParser('start = "a" "b" / "a"', options);
expect(parser).toParse("a", "a");
});
});
});
describe("labeled matching", function() {
varyAll(function(options) {
it("delegates to the expression", function() {

@ -23,26 +23,6 @@ testWithVaryingTrackLineAndColumn("choices", function(options) {
doesNotParse(parser, "d");
});
testWithVaryingTrackLineAndColumn("sequences", function(options) {
var emptySequenceParser = PEG.buildParser('start = ', options);
parses(emptySequenceParser, "", []);
doesNotParse(emptySequenceParser, "abc");
var nonEmptySequenceParser = PEG.buildParser('start = "a" "b" "c"', options);
parses(nonEmptySequenceParser, "abc", ["a", "b", "c"]);
doesNotParse(nonEmptySequenceParser, "");
doesNotParse(nonEmptySequenceParser, "ab");
doesNotParse(nonEmptySequenceParser, "abcd");
doesNotParse(nonEmptySequenceParser, "efg");
/*
* Test that the parsing position returns after unsuccessful parsing of a
* sequence.
*/
var posTestParser = PEG.buildParser('start = ("a" "b") / "a"', options);
parses(posTestParser, "a", "a");
});
testWithVaryingTrackLineAndColumn("initializer", function(options) {
var variableInActionParser = PEG.buildParser(
'{ a = 42; }; start = "a" { return a; }',

Loading…
Cancel
Save