|
|
@ -1219,8 +1219,9 @@ describe("generated parser behavior", function() { |
|
|
|
); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("a", { |
|
|
|
message: 'Expected a.', |
|
|
|
message: 'Expected a but "a" found.', |
|
|
|
expected: [{ type: "other", description: "a" }], |
|
|
|
found: "a", |
|
|
|
location: { |
|
|
|
start: { offset: 0, line: 1, column: 1 }, |
|
|
|
end: { offset: 1, line: 1, column: 2 } |
|
|
@ -1239,8 +1240,9 @@ describe("generated parser behavior", function() { |
|
|
|
].join("\n"), options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("a", { |
|
|
|
message: 'Expected a.', |
|
|
|
message: 'Expected a but "a" found.', |
|
|
|
expected: [{ type: "other", description: "a" }], |
|
|
|
found: "a", |
|
|
|
location: { |
|
|
|
start: { offset: 1, line: 1, column: 2 }, |
|
|
|
end: { offset: 2, line: 1, column: 3 } |
|
|
@ -1258,6 +1260,7 @@ describe("generated parser behavior", function() { |
|
|
|
|
|
|
|
expect(parser).toFailToParse("a", { |
|
|
|
message: "a", |
|
|
|
found: "a", |
|
|
|
expected: null, |
|
|
|
location: { |
|
|
|
start: { offset: 0, line: 1, column: 1 }, |
|
|
@ -1279,6 +1282,7 @@ describe("generated parser behavior", function() { |
|
|
|
expect(parser).toFailToParse("a", { |
|
|
|
message: "a", |
|
|
|
expected: null, |
|
|
|
found: "a", |
|
|
|
location: { |
|
|
|
start: { offset: 1, line: 1, column: 2 }, |
|
|
|
end: { offset: 2, line: 1, column: 3 } |
|
|
@ -1395,12 +1399,26 @@ describe("generated parser behavior", function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("found string reporting", function() { |
|
|
|
it("reports found string correctly at the end of input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("", { found: null }); |
|
|
|
}); |
|
|
|
|
|
|
|
it("reports found string correctly in the middle of input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("b", { found: "b" }); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("message building", function() { |
|
|
|
it("builds message correctly with no alternative", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("ab", { |
|
|
|
message: 'Expected end of input.' |
|
|
|
message: 'Expected end of input but "b" found.' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -1408,7 +1426,7 @@ describe("generated parser behavior", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("b", { |
|
|
|
message: 'Expected "a".' |
|
|
|
message: 'Expected "a" but "b" found.' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -1416,16 +1434,32 @@ describe("generated parser behavior", function() { |
|
|
|
var parser = peg.generate('start = "a" / "b" / "c"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("d", { |
|
|
|
message: 'Expected "a", "b" or "c".' |
|
|
|
message: 'Expected "a", "b" or "c" but "d" found.' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("builds message correctly at the end of input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("", { |
|
|
|
message: 'Expected "a" but end of input found.' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("builds message correctly in the middle of input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("b", { |
|
|
|
message: 'Expected "a" but "b" found.' |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("position reporting", function() { |
|
|
|
it("reports position correctly with no trailing input", function() { |
|
|
|
it("reports position correctly at the end of input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("b", { |
|
|
|
expect(parser).toFailToParse("", { |
|
|
|
location: { |
|
|
|
start: { offset: 0, line: 1, column: 1 }, |
|
|
|
end: { offset: 0, line: 1, column: 1 } |
|
|
@ -1433,13 +1467,24 @@ describe("generated parser behavior", function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("reports position correctly in the middle of input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("b", { |
|
|
|
location: { |
|
|
|
start: { offset: 0, line: 1, column: 1 }, |
|
|
|
end: { offset: 1, line: 1, column: 2 } |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("reports position correctly with trailing input", function() { |
|
|
|
var parser = peg.generate('start = "a"', options); |
|
|
|
|
|
|
|
expect(parser).toFailToParse("aa", { |
|
|
|
location: { |
|
|
|
start: { offset: 1, line: 1, column: 2 }, |
|
|
|
end: { offset: 1, line: 1, column: 2 } |
|
|
|
end: { offset: 2, line: 1, column: 3 } |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1455,7 +1500,7 @@ describe("generated parser behavior", function() { |
|
|
|
expect(parser).toFailToParse("1\n2\n\n3\n\n\n4 5 x", { |
|
|
|
location: { |
|
|
|
start: { offset: 13, line: 7, column: 5 }, |
|
|
|
end: { offset: 13, line: 7, column: 5 } |
|
|
|
end: { offset: 14, line: 7, column: 6 } |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
@ -1463,13 +1508,13 @@ describe("generated parser behavior", function() { |
|
|
|
expect(parser).toFailToParse("1\nx", { // Old Mac
|
|
|
|
location: { |
|
|
|
start: { offset: 2, line: 2, column: 1 }, |
|
|
|
end: { offset: 2, line: 2, column: 1 } |
|
|
|
end: { offset: 3, line: 2, column: 2 } |
|
|
|
} |
|
|
|
}); |
|
|
|
expect(parser).toFailToParse("1\r\nx", { // Windows
|
|
|
|
location: { |
|
|
|
start: { offset: 3, line: 2, column: 1 }, |
|
|
|
end: { offset: 3, line: 2, column: 1 } |
|
|
|
end: { offset: 4, line: 2, column: 2 } |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|