コード例 #1
0
        public void Neglect()
        {
            Pattern pattern = Not(Many(';'));

            ResultAssert.Captures("123456789", pattern.Consume("123456789;"));
            ResultAssert.Fails(pattern.Consume(";"));
        }
コード例 #2
0
        public void Double_Negator()
        {
            Pattern pattern = Not(Not("Hello"));

            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Fails(pattern.Consume("World"));
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
ファイル: RegexAdapterTests.cs プロジェクト: BaisilG/Patterns
        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"));
        }
コード例 #6
0
        public void Consume()
        {
            Pattern pattern = Many(' ');

            ResultAssert.Captures(" ", pattern.Consume(" Hi!"));
            ResultAssert.Captures("    ", pattern.Consume("    Hi!"));
            ResultAssert.Fails(pattern.Consume("Hi!  "));
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
ファイル: RepeaterTests.cs プロジェクト: BaisilG/Patterns
        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! "));
        }
コード例 #9
0
        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(""));
        }
コード例 #10
0
ファイル: RepeaterTests.cs プロジェクト: BaisilG/Patterns
        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! "));
        }
コード例 #11
0
        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"));
        }
コード例 #12
0
ファイル: FuzzerTests.cs プロジェクト: BaisilG/Patterns
        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"));
        }
コード例 #13
0
ファイル: LiteralTests.cs プロジェクト: BaisilG/Patterns
        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."));
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        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"));
        }
コード例 #16
0
ファイル: ConcatenatorTests.cs プロジェクト: BaisilG/Patterns
        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"));
        }
コード例 #17
0
        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"));
        }
コード例 #18
0
        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(""));
        }
コード例 #19
0
ファイル: LiteralTests.cs プロジェクト: BaisilG/Patterns
 public void Consume_String_FromString()
 {
     ResultAssert.Captures("Hello", "Hello".Consume("Hello World"));
     ResultAssert.Fails("Hello".Consume("Hell"));
     ResultAssert.Fails("Hello".Consume("Bacon"));
 }