public void Neglect() { Pattern pattern = Not(Many(';')); ResultAssert.Captures("123456789", pattern.Consume("123456789;")); ResultAssert.Fails(pattern.Consume(";")); }
public void Double_Negator() { Pattern pattern = Not(Not("Hello")); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Fails(pattern.Consume("World")); }
public void Consume() { Pattern pattern = "Hello".Or("Goodbye"); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Captures("Goodbye", pattern.Consume("Goodbye")); ResultAssert.Fails(pattern.Consume("!")); ResultAssert.Fails(pattern.Consume("How are you?")); pattern = "Hello".Or("Hi").Or("Howdy"); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Captures("Hi", pattern.Consume("Hi")); ResultAssert.Captures("Howdy", pattern.Consume("Howdy")); ResultAssert.Fails(pattern.Consume("Goodbye")); pattern = OneOf("Hello", "Hi", "Howdy"); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Captures("Hi", pattern.Consume("Hi")); ResultAssert.Captures("Howdy", pattern.Consume("Howdy")); ResultAssert.Fails(pattern.Consume("Goodbye")); pattern = OneOf <Enum>(); ResultAssert.Captures("First", pattern.Consume("First")); ResultAssert.Captures("Second", pattern.Consume("Second")); ResultAssert.Captures("Third", pattern.Consume("Third")); ResultAssert.Fails(pattern.Consume("Fourth")); }
public void Nested_Consume() { Pattern pattern = NestedRange("if", "end if"); ResultAssert.Captures("if\nif\nend if\nbacon\nend if", pattern.Consume("if\nif\nend if\nbacon\nend if\nfoobar")); ResultAssert.Fails(pattern.Consume("if\nif\nend if\nbacon\nfoobar")); }
public void Consume() { Pattern pattern = new Regex("^hello").AsPattern(); ResultAssert.Captures("hello", pattern.Consume("hello")); ResultAssert.Captures("hello", pattern.Consume("hello world")); ResultAssert.Fails(pattern.Consume("hel")); }
public void Consume() { Pattern pattern = Many(' '); ResultAssert.Captures(" ", pattern.Consume(" Hi!")); ResultAssert.Captures(" ", pattern.Consume(" Hi!")); ResultAssert.Fails(pattern.Consume("Hi! ")); }
public void Neglect() { Pattern pattern = Not("Hello".Or("Goodbye")); ResultAssert.Captures("World", pattern.Consume("Worldeater")); ResultAssert.Fails(pattern.Consume("Hello")); ResultAssert.Fails(pattern.Consume("Goodbye")); }
public void Consume() { Pattern pattern = "Hi! ".AsPattern() * 2; ResultAssert.Captures("Hi! Hi! ", pattern.Consume("Hi! Hi! ")); ResultAssert.Captures("Hi! Hi! ", pattern.Consume("Hi! Hi! Hi!")); ResultAssert.Fails(pattern.Consume("Hi! Bye! ")); }
public void Double_Spanner() { Pattern pattern = Many(Many("hi")); ResultAssert.Captures("hi", pattern.Consume("hi")); ResultAssert.Captures("hihi", pattern.Consume("hihi")); ResultAssert.Captures("hihihi", pattern.Consume("hihihi")); ResultAssert.Fails(pattern.Consume("")); }
public void Neglect() { Pattern pattern = Not("Hi! ".AsPattern() * 2); ResultAssert.Captures("Oh! No! ", pattern.Consume("Oh! No! ")); ResultAssert.Captures("Oh? Hi! ", pattern.Consume("Oh? Hi! ")); ResultAssert.Captures("Hi! Ho! ", pattern.Consume("Hi! Ho! ")); ResultAssert.Fails(pattern.Consume("H! Hi! ")); }
public void Alternate_Repeater() { Pattern pattern = "Hi".Or("Bye").Then(' ').Repeat(2); ResultAssert.Captures("Hi Bye ", pattern.Consume("Hi Bye Hi ")); ResultAssert.Captures("Hi Hi ", pattern.Consume("Hi Hi Hi ")); ResultAssert.Captures("Hi Hi ", pattern.Consume("Hi Hi ")); ResultAssert.Fails(pattern.Consume("Hi Hi")); }
public void Consume() { Pattern pattern = Fuzzy("Bob"); ResultAssert.Captures("Bob", pattern.Consume("Bob")); ResultAssert.Captures("bob", pattern.Consume("bob")); ResultAssert.Captures("Mob", pattern.Consume("Mob")); ResultAssert.Captures("mob", pattern.Consume("mob")); ResultAssert.Fails(pattern.Consume("Mom")); }
public void Neglect() { Pattern pattern = Not("Hello"); ResultAssert.Captures("Oh no", pattern.Consume("Oh no!")); ResultAssert.Captures("Oh no", pattern.Consume("Oh no?")); ResultAssert.Fails(pattern.Consume("Hello")); ResultAssert.Fails(pattern.Consume("Hello!")); ResultAssert.Fails(pattern.Consume("Hello.")); }
public void Backtracking() { Pattern end1 = "end".Then(Many(' ')).Then("first"); Pattern end2 = "end".Then(Many(' ')).Then("second"); Source source = new Source("end second"); //f backtracking doesn't occur, parsing end2 will fail, because "end" and the space will have been consumed ResultAssert.Fails(end1.Consume(ref source)); ResultAssert.Captures("end second", end2.Consume(ref source)); }
public void Mutate_And_Consume() { Pattern pattern = Mutable(); pattern.Then("Hello").Then(' ').Then("world"); ResultAssert.Captures("Hello world", pattern.Consume("Hello world")); Not(pattern).Seal(); ResultAssert.Captures("Bacon cakes", pattern.Consume("Bacon cakes")); ResultAssert.Fails(pattern.Consume("Hello world")); }
public void Consume() { Pattern pattern = "Hello".Then(' ').Then("world"); ResultAssert.Captures("Hello world", pattern.Consume("Hello world")); ResultAssert.Fails(pattern.Consume("Goodbye world")); pattern = "Goodbye".Then(' ').Then("world"); ResultAssert.Captures("Goodbye world", pattern.Consume("Goodbye world")); ResultAssert.Fails(pattern.Consume("Hello world")); }
public void Identifier() { Pattern pattern = Check( (c) => c.IsLetter(), true, (c) => c.IsLetter() || c == '_', true, (c) => c.IsLetter() || c == '_', false); ResultAssert.Captures("hello", pattern.Consume("hello")); ResultAssert.Captures("example_name", pattern.Consume("example_name")); ResultAssert.Fails(pattern.Consume("_fail")); }
public void RightRecursion() { Pattern pattern = Mutable(); pattern.Then("hi!").Then(EndOfSource | pattern); pattern.Seal(); ResultAssert.Captures("hi!", pattern.Consume("hi!")); ResultAssert.Captures("hi!hi!", pattern.Consume("hi!hi!")); ResultAssert.Captures("hi!hi!hi!", pattern.Consume("hi!hi!hi!")); ResultAssert.Captures("hi!hi!hi!hi!", pattern.Consume("hi!hi!hi!hi!")); ResultAssert.Fails(pattern.Consume("")); }
public void Consume_String_FromString() { ResultAssert.Captures("Hello", "Hello".Consume("Hello World")); ResultAssert.Fails("Hello".Consume("Hell")); ResultAssert.Fails("Hello".Consume("Bacon")); }