public void Should_match_the_string_at_the_start_of_the_input()
        {
            const string hello = "Hello";

            var parser = new ConstantStringParser(hello);
            var parsed = parser.ParseString("Hello, World.");

            Assert.IsTrue(parsed.HasValue);
            Assert.AreEqual(hello, parsed.Value);
        }
Example #2
0
        public void Should_match_the_string_at_the_start_of_the_input()
        {
            const string hello = "Hello";

            var parser = new ConstantStringParser(hello);
            var parsed = parser.ParseString("Hello, World.");

            Assert.IsTrue(parsed.HasValue);
            Assert.AreEqual(hello, parsed.Value);
        }
Example #3
0
        public void Should_support_a_single_parser()
        {
            var parser = new ConstantStringParser("Hello");

            var visualizer = new ParserVisualizer();
            parser.Accept(visualizer);
            string text = visualizer.ToString();

            string expected = @"(String) == ""Hello""";
            Assert.AreEqual(expected, text);
        }
Example #4
0
        public void Should_not_match_without_whitespace_filter()
        {
            string subject = "   \t\r\n\tHello";

            var helloParser = new ConstantStringParser("Hello");

            var parser = from value in helloParser
                         select value;

            var result = parser.ParseString(subject);

            Assert.IsFalse(result.HasValue);
        }
Example #5
0
        public void Should_not_match_without_whitespace_filter()
        {
            string subject = "   \t\r\n\tHello";

            var helloParser = new ConstantStringParser("Hello");

            var parser = from value in helloParser
                         select value;

            var result = parser.ParseString(subject);

            Assert.IsFalse(result.HasValue);
        }
Example #6
0
        public void Should_support_a_single_parser()
        {
            var parser = new ConstantStringParser("Hello");

            var visualizer = new ParserVisualizer();

            parser.Accept(visualizer);
            string text = visualizer.ToString();

            string expected = @"(String) == ""Hello""";

            Assert.AreEqual(expected, text);
        }
Example #7
0
        public void Should_not_match_digits()
        {
            const string subject = "v120";

            var sp = new ConstantStringParser("X");

            var parser = from x in sp.Regex(@"\d+")
                         select x;

            var result = parser.ParseString(subject);

            Assert.IsFalse(result.HasValue);
            Assert.AreEqual(0, result.Next.Offset);
        }
Example #8
0
        public void Should_not_match_digits()
        {
            const string subject = "v120";

            var sp = new ConstantStringParser("X");

            var parser = from x in sp.Regex(@"\d+")
                         select x;

            var result = parser.ParseString(subject);

            Assert.IsFalse(result.HasValue);
            Assert.AreEqual(0, result.Next.Offset);
        }
        public void Should_continue_with_the_next_string_match()
        {
            const string hello = "Hello";

            var parser = new ConstantStringParser(hello);
            var parsed = parser.ParseString("Hello, World.");

            const string world = ", World";

            var nextParser = new ConstantStringParser(world);
            var nextParsed = nextParser.Parse(parsed.Next);

            Assert.IsTrue(nextParsed.HasValue);
            Assert.AreEqual(world, nextParsed.Value);
        }
Example #10
0
        public void Should_continue_with_the_next_string_match()
        {
            const string hello = "Hello";

            var parser = new ConstantStringParser(hello);
            var parsed = parser.ParseString("Hello, World.");

            const string world = ", World";

            var nextParser = new ConstantStringParser(world);
            var nextParsed = nextParser.Parse(parsed.Next);

            Assert.IsTrue(nextParsed.HasValue);
            Assert.AreEqual(world, nextParsed.Value);
        }
Example #11
0
        public void Should_be_possible()
        {
            const string subject = "Hello, World.";

            var constant = "Hello";

            var helloParser = new ConstantStringParser(constant);

            var query = from hello in helloParser
                        select hello;

            var parsed = query.ParseString(subject);

            Assert.IsTrue(parsed.HasValue);
            Assert.AreEqual(constant, parsed.Value);
        }
Example #12
0
        public void Should_be_possible()
        {
            const string subject = "Hello, World.";

            var constant = "Hello";

            var helloParser = new ConstantStringParser(constant);

            var query = from hello in helloParser
                        select hello;

            var parsed = query.ParseString(subject);

            Assert.IsTrue(parsed.HasValue);
            Assert.AreEqual(constant, parsed.Value);
        }