public void Double_Optor() { Pattern pattern = Maybe(Maybe("Hello")); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Captures("", pattern.Consume("World")); }
public void Neglect() { Pattern pattern = Not(Many(';')); ResultAssert.Captures("123456789", pattern.Consume("123456789;")); ResultAssert.Fails(pattern.Consume(";")); }
public void Alternate_Spanner() { Pattern pattern = Many(SpaceSeparator.Or('\t')); ResultAssert.Captures(" \t ", pattern.Consume(" \t ")); ResultAssert.Captures(" \t ", pattern.Consume(" \t hi")); }
public void Neglect() { Pattern pattern = Not(Maybe("Hello")); ResultAssert.Captures("", pattern.Consume("Hello")); ResultAssert.Captures("World", pattern.Consume("World")); }
public void Consume_Insensitive() { Pattern pattern = "Hello".With(Case.Insensitive).Then(' '.With(Case.Insensitive)).Then("World".With(Case.Insensitive)); ResultAssert.Captures("HELLO WORLD", pattern.Consume("HELLO WORLD")); ResultAssert.Captures("hello world", pattern.Consume("hello world")); }
public void Consume() { Pattern pattern = Maybe("Hello"); ResultAssert.Captures("Hello", pattern.Consume("Hello World")); ResultAssert.Captures("", pattern.Consume("Goodbye World")); }
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 Simple_Consume() { Pattern pattern = Range("Hello", ';'); ResultAssert.Captures("Hello;", pattern.Consume("Hello;")); ResultAssert.Captures("Hello World;", pattern.Consume("Hello 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 Optional_Spanner() { Pattern pattern = Maybe(Many(' ')); ResultAssert.Captures(" ", pattern.Consume(" Hello")); ResultAssert.Captures("", pattern.Consume("Hello")); }
public void ReadUntilEndOfLine() { Pattern pattern = Many(Not(';' | LineTerminator)); ResultAssert.Captures("hello", pattern.Consume("hello")); ResultAssert.Captures("hello", pattern.Consume("hello\nworld")); }
public void Double_Negator() { Pattern pattern = Not(Not("Hello")); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Fails(pattern.Consume("World")); }
public void Comment() { Pattern pattern = LineComment("--"); ResultAssert.Captures("--This is a comment", pattern.Consume("--This is a comment")); ResultAssert.Captures("--This is also a comment", pattern.Consume("--This is also a comment\nExample_Function_Call();")); }
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 = 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 = "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 StoreAndRestore() { Source source = new Source("hello world"); SourceState state = source.Store(); ResultAssert.Captures("hello", "hello".Consume(ref source)); source.Restore(state); ResultAssert.Captures("hello", "hello".Consume(ref source)); }
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 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 Escaped_Consume() { Pattern pattern = Range("\"", "\"", "\\\""); ResultAssert.Captures("\"\"", pattern.Consume("\"\"")); ResultAssert.Captures("\"H\"", pattern.Consume("\"H\"i")); ResultAssert.Captures("\"Hello\"", pattern.Consume("\"Hello\"")); ResultAssert.Captures("\"Hello\\\"Goodbye\"", pattern.Consume("\"Hello\\\"Goodbye\"")); }
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 StringLiteral() { Pattern pattern = Pattern.StringLiteral("\"", "\\\""); ResultAssert.Captures("\"Hello World\"", pattern.Consume("\"Hello World\"")); ResultAssert.Captures("\"Hello World\"", pattern.Consume("\"Hello World\" Bacon")); ResultAssert.Captures("\"Hello\\\"World\"", pattern.Consume("\"Hello\\\"World\"")); ResultAssert.Captures("\"Hello\\\"World\"", pattern.Consume("\"Hello\\\"World\" Bacon")); }
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 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 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_Rune_FromSource() { Source source = new Source("hello"); ResultAssert.Captures("h", new Rune('h').Consume(ref source)); ResultAssert.Captures("ello", "ello".Consume(ref source)); source = new Source("𝄞abc"); ResultAssert.Captures("𝄞", new Rune(0x1D11E).Consume(ref source)); ResultAssert.Captures("abc", "abc".Consume(ref source)); }
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 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")); }