コード例 #1
0
        public void AttributeSelector_MissingEndBracket()
        {
            string            test = "[foo=";
            ITextProvider     tp   = new StringTextProvider(test);
            TokenStream       ts   = Helpers.MakeTokenStream(tp);
            AttributeSelector attributeSelector = new AttributeSelector();

            Assert.IsTrue(attributeSelector.Parse(new ItemFactory(tp, null), tp, ts));
            Assert.IsNotNull(attributeSelector.OpenBracket);
            Assert.IsNull(attributeSelector.CloseBracket);
        }
コード例 #2
0
        public void AttributeSelector_AttributeContainsString()
        {
            string            test = "[  title  *=  \"hello\"  ]:ignore";
            ITextProvider     tp   = new StringTextProvider(test);
            TokenStream       ts   = Helpers.MakeTokenStream(tp);
            AttributeSelector attributeSelector = new AttributeSelector();

            Assert.IsTrue(attributeSelector.Parse(new ItemFactory(tp, null), tp, ts), "Valid CSS '{0}' parsed incorrectly", test);
            Assert.IsNotNull(attributeSelector.OpenBracket, "OpenBracket not parsed for CSS : '{0}'", test);
            Assert.IsNotNull(attributeSelector.CloseBracket, "CloseBracket not parsed for CSS : '{0}'", test);
            Assert.IsTrue(tp.CompareTo(attributeSelector.AttributeName.Start, "title", ignoreCase: false), "AttributeName not parsed for CSS : '{0}'", test);
            Assert.AreEqual(CssTokenType.ContainsString, attributeSelector.Operation.TokenType);
            Assert.IsTrue(attributeSelector.IsValid);
        }
コード例 #3
0
        public void AttributeSelector_AttributeEndsWith()
        {
            string            test = "[href$=\".html\"][ignore=this]";
            ITextProvider     tp   = new StringTextProvider(test);
            TokenStream       ts   = Helpers.MakeTokenStream(tp);
            AttributeSelector attributeSelector = new AttributeSelector();

            Assert.IsTrue(attributeSelector.Parse(new ItemFactory(tp, null), tp, ts), "Valid CSS '{0}' parsed incorrectly", test);
            Assert.IsNotNull(attributeSelector.OpenBracket, "OpenBracket not parsed for CSS : '{0}'", test);
            Assert.IsNotNull(attributeSelector.CloseBracket, "CloseBracket not parsed for CSS : '{0}'", test);
            Assert.IsTrue(tp.CompareTo(attributeSelector.AttributeName.Start, "href", ignoreCase: false), "AttributeName not parsed for CSS : '{0}'", test);
            Assert.AreEqual(CssTokenType.EndsWith, attributeSelector.Operation.TokenType);
            Assert.IsTrue(attributeSelector.IsValid);
        }
コード例 #4
0
        public void AttributeSelectorAttributeOneOfValue()
        {
            string            test = "[rel ~= 'copyright']";
            ITextProvider     tp   = new StringTextProvider(test);
            TokenStream       ts   = Helpers.MakeTokenStream(tp);
            AttributeSelector attributeSelector = new AttributeSelector();

            Assert.IsTrue(attributeSelector.Parse(new ItemFactory(tp, null), tp, ts), "Valid CSS '{0}' parsed incorrectly", test);
            Assert.IsNotNull(attributeSelector.OpenBracket, "OpenBracket not parsed for CSS : '{0}'", test);
            Assert.IsNotNull(attributeSelector.CloseBracket, "CloseBracket not parsed for CSS : '{0}'", test);
            Assert.IsTrue(tp.CompareTo(attributeSelector.AttributeName.Start, "rel", ignoreCase: false), "AttributeName not parsed for CSS : '{0}'", test);
            Assert.AreEqual(CssTokenType.OneOf, attributeSelector.Operation.TokenType, "CssTokenType.OneOf not parsed for CSS : '{0}'", test);
            Assert.IsTrue(attributeSelector.IsValid);
        }
コード例 #5
0
        public void AttributeSelector_AttributeOrSeparatorNoNS()
        {
            string            test = "[|att=val]";
            ITextProvider     tp   = new StringTextProvider(test);
            TokenStream       ts   = Helpers.MakeTokenStream(tp);
            AttributeSelector attributeSelector = new AttributeSelector();

            Assert.IsTrue(attributeSelector.Parse(new ItemFactory(tp, null), tp, ts), "Valid CSS '{0}' parsed incorrectly", test);
            Assert.IsTrue(attributeSelector.IsValid);
            Assert.IsNotNull(attributeSelector.OpenBracket, "OpenBracket not parsed for CSS : '{0}'", test);
            Assert.IsNotNull(attributeSelector.CloseBracket, "CloseBracket not parsed for CSS : '{0}'", test);

            Assert.IsNotNull(attributeSelector.AttributeName.Separator, test, "AttributeName.Separator  not parsed for CSS : '{0}'", test);
            Assert.IsTrue(tp.CompareTo(attributeSelector.AttributeName.Name.Start, "att", ignoreCase: false), "AttributeName not parsed for CSS : '{0}'", test);
            Assert.IsTrue(tp.CompareTo(attributeSelector.AttributeValue.Start, "val", ignoreCase: false), "Value not parsed for CSS : '{0}'", test);
        }
コード例 #6
0
        public void AttributeSelector_Invalid()
        {
            string[] tests = new string[]
            {
                ".a",
                "#123",
                "a",
                "*",
                "+",
                ">",
                "|foo",
                "foo]"
            };

            foreach (string test in tests)
            {
                ITextProvider     tp = new StringTextProvider(test);
                TokenStream       ts = Helpers.MakeTokenStream(tp);
                AttributeSelector attributeSelector = new AttributeSelector();
                Assert.IsFalse(attributeSelector.Parse(new ItemFactory(tp, null), tp, ts));
            }
        }