Exemple #1
0
        public void OptionallyQuoted()
        {
            scanner = @"key[value='this ""is \' a quoted value']";
            StringScanner inner = scanner.ExpectAlpha()
                                  .Get(MatchFunctions.Bounded);

            scanner.AssertFinished();

            inner.Expect(MatchFunctions.HTMLAttribute)
            .Expect("=");

            var optQuote = new OptionallyQuoted();

            optQuote.Terminators = "]";

            string text = inner.Get(optQuote);

            Assert.AreEqual("this \"is ' a quoted value", text, "Got the right text");

            inner.Text = @"this ""is \' a quoted value";
            text       = inner.Get(optQuote);
            Assert.AreEqual("this \"is \\' a quoted value", text, "Got the right text without quotes");

            inner.Text = @"""this is \"" a quoted value""";
            text       = inner.Get(optQuote);
            Assert.AreEqual("this is \" a quoted value", text, "Got the right text with quotes");
        }
Exemple #2
0
        public void BuiltInSelectors()
        {
            scanner = @"someSelect[attr-bute= 'this ""is \' a quoted value']";

            var text = scanner.Get(MatchFunctions.HTMLTagName);

            Assert.AreEqual("someSelect", text, "Got first word");

            StringScanner innerScanner = scanner.Get(MatchFunctions.BoundedWithQuotedContent);

            Assert.IsTrue(scanner.Finished, "Outer scanner finished");
            Assert.AreEqual(@"attr-bute= 'this ""is \' a quoted value'", innerScanner.Text, "Inner scanner text is right");

            text = innerScanner.Get(MatchFunctions.HTMLAttribute);
            Assert.AreEqual("attr-bute", text, "Got the attribute name");
            innerScanner.Expect("=");
            text = innerScanner.Get(MatchFunctions.Quoted);
            Assert.AreEqual(@"this ""is ' a quoted value", text, "Quotes were dequoted");
            Assert.IsTrue(innerScanner.Finished, "It's finished after we got the last text");

            scanner = @"<comment>How's complex bounding working?</comment> the end";
            text    = scanner.GetBoundedBy("<comment>", "</comment>");
            Assert.AreEqual(@"How's complex bounding working?", text, "Complex bounding worked");
            Assert.AreEqual(' ', scanner.NextChar, "At the right place");

            Assert.IsTrue(scanner.ExpectAlpha().ExpectAlpha().Finished, "At the end");
        }
Exemple #3
0
        public void Bounded()
        {
            scanner = @"<comment>How's complex bounding working?</comment> the end";
            string text = scanner.GetBoundedBy("<comment>", "</comment>");

            Assert.AreEqual(@"How's complex bounding working?", text, "Complex bounding worked");
            Assert.AreEqual(' ', scanner.NextChar, "At the right place");
            Assert.IsTrue(scanner.ExpectAlpha().ExpectAlpha().Finished, "At the end");

            scanner = "some(complex(formula+2))";
            scanner.ExpectAlpha();
            text = scanner.GetBoundedBy('(', false);
            Assert.AreEqual("complex(formula+2)", text, "OK with inner parens");
        }
        public void Bounded()
        {
          
            scanner = @"<comment>How's complex bounding working?</comment> the end";
            string text = scanner.GetBoundedBy("<comment>", "</comment>");
            Assert.AreEqual(@"How's complex bounding working?", text, "Complex bounding worked");
            Assert.AreEqual(' ', scanner.NextChar, "At the right place");
            Assert.IsTrue(scanner.ExpectAlpha().ExpectAlpha().Finished, "At the end");

            scanner = "some(complex(formula+2))";
            scanner.ExpectAlpha();
            text = scanner.GetBoundedBy('(', false);
            Assert.AreEqual("complex(formula+2)", text, "OK with inner parens");


        }
        public void OptionallyQuoted()
        {
            scanner=@"key[value='this ""is \' a quoted value']";
            StringScanner inner = scanner.ExpectAlpha()
                .Get(MatchFunctions.Bounded);

            scanner.AssertFinished();

            inner.Expect(MatchFunctions.HTMLAttribute)
                .Expect("=");

            var optQuote = new OptionallyQuoted();
            optQuote.Terminators="]";

            string text = inner.Get(optQuote);
            Assert.AreEqual("this \"is ' a quoted value",text,"Got the right text");

            inner.Text = @"this ""is \' a quoted value";
            text = inner.Get(optQuote);
            Assert.AreEqual("this \"is \\' a quoted value",text, "Got the right text without quotes");

            inner.Text = @"""this is \"" a quoted value""";
            text = inner.Get(optQuote);
            Assert.AreEqual("this is \" a quoted value", text, "Got the right text with quotes");


        }
        public void BuiltInSelectors()
        {
            scanner=@"someSelect[attr-bute= 'this ""is \' a quoted value']";

            var text = scanner.Get(MatchFunctions.HTMLTagName);
            Assert.AreEqual("someSelect", text, "Got first word");

            StringScanner innerScanner = scanner.Get(MatchFunctions.BoundedWithQuotedContent);
            Assert.IsTrue(scanner.Finished, "Outer scanner finished");
            Assert.AreEqual(@"attr-bute= 'this ""is \' a quoted value'", innerScanner.Text, "Inner scanner text is right");

            text = innerScanner.Get(MatchFunctions.HTMLAttribute);
            Assert.AreEqual("attr-bute", text, "Got the attribute name");
            innerScanner.Expect("=");
            text = innerScanner.Get(MatchFunctions.Quoted);
            Assert.AreEqual(@"this ""is ' a quoted value", text, "Quotes were dequoted");
            Assert.IsTrue(innerScanner.Finished, "It's finished after we got the last text");

            scanner = @"<comment>How's complex bounding working?</comment> the end";
            text = scanner.GetBoundedBy("<comment>", "</comment>");
            Assert.AreEqual(@"How's complex bounding working?", text, "Complex bounding worked");
            Assert.AreEqual(' ', scanner.NextChar, "At the right place");
            
            Assert.IsTrue(scanner.ExpectAlpha().ExpectAlpha().Finished, "At the end");


        }