Behavior specs cleanup: Improve character class specs
This commit is contained in:
parent
54191fbf12
commit
74be12c657
|
@ -282,58 +282,69 @@ describe("generated parser behavior", function() {
|
|||
});
|
||||
|
||||
describe("character class", function() {
|
||||
it("matches empty class correctly", function() {
|
||||
describe("matching", function() {
|
||||
it("matches empty classes", function() {
|
||||
var parser = PEG.buildParser('start = []', options);
|
||||
|
||||
expect(parser).toFailToParse("a");
|
||||
});
|
||||
|
||||
it("matches class with a character list correctly", function() {
|
||||
it("matches classes with a character list", function() {
|
||||
var parser = PEG.buildParser('start = [abc]', options);
|
||||
|
||||
expect(parser).toParse("a", "a");
|
||||
expect(parser).toParse("b", "b");
|
||||
expect(parser).toParse("c", "c");
|
||||
expect(parser).toParse("a");
|
||||
expect(parser).toParse("b");
|
||||
expect(parser).toParse("c");
|
||||
expect(parser).toFailToParse("d");
|
||||
});
|
||||
|
||||
it("matches class with a range correctly", function() {
|
||||
it("matches classes with a character range", function() {
|
||||
var parser = PEG.buildParser('start = [a-c]', options);
|
||||
|
||||
expect(parser).toParse("a", "a");
|
||||
expect(parser).toParse("b", "b");
|
||||
expect(parser).toParse("c", "c");
|
||||
expect(parser).toParse("a");
|
||||
expect(parser).toParse("b");
|
||||
expect(parser).toParse("c");
|
||||
expect(parser).toFailToParse("d");
|
||||
});
|
||||
|
||||
it("matches inverted class correctly", function() {
|
||||
it("matches inverted classes", function() {
|
||||
var parser = PEG.buildParser('start = [^a]', options);
|
||||
|
||||
expect(parser).toFailToParse("a");
|
||||
expect(parser).toParse("b", "b");
|
||||
expect(parser).toParse("b");
|
||||
});
|
||||
|
||||
it("is case sensitive without the \"i\" flag", function() {
|
||||
var parser = PEG.buildParser('start = [a]', options);
|
||||
|
||||
expect(parser).toParse("a", "a");
|
||||
expect(parser).toParse("a");
|
||||
expect(parser).toFailToParse("A");
|
||||
});
|
||||
|
||||
it("is case insensitive with the \"i\" flag", function() {
|
||||
var parser = PEG.buildParser('start = [a]i', options);
|
||||
|
||||
expect(parser).toParse("a", "a");
|
||||
expect(parser).toParse("A", "A");
|
||||
expect(parser).toParse("a");
|
||||
expect(parser).toParse("A");
|
||||
});
|
||||
});
|
||||
|
||||
it("advances position on success", function() {
|
||||
describe("when it matches", function() {
|
||||
it("returns the matched character", function() {
|
||||
var parser = PEG.buildParser('start = [a]', options);
|
||||
|
||||
expect(parser).toParse("a", "a");
|
||||
});
|
||||
|
||||
it("advances parse position past the matched character", function() {
|
||||
var parser = PEG.buildParser('start = [a] .', options);
|
||||
|
||||
expect(parser).toParse("ab", ["a", "b"]);
|
||||
expect(parser).toParse("ab");
|
||||
});
|
||||
});
|
||||
|
||||
it("sets expectation correctly on failure", function() {
|
||||
describe("when it doesn't match", function() {
|
||||
it("reports match failure and records an expectation of type \"class\"", function() {
|
||||
var parser = PEG.buildParser('start = [a]', options);
|
||||
|
||||
expect(parser).toFailToParse("b", {
|
||||
|
@ -341,6 +352,7 @@ describe("generated parser behavior", function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("dot", function() {
|
||||
it("matches correctly", function() {
|
||||
|
|
Loading…
Reference in a new issue