Exemplo n.º 1
0
        public void Declaration_ParseTest2()
        {
            string        text   = "-moz-image: url(image.jpg) -25 bar baz";
            ITextProvider tp     = new StringTextProvider(text);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Declaration   d      = new Declaration();

            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));

            Assert.AreEqual(0, d.Start);
            Assert.AreEqual(text.Length, d.AfterEnd);

            Assert.AreEqual(6, d.Children.Count);
            Assert.AreEqual(null, d.Semicolon);

            Assert.IsInstanceOfType(d.Children[0], typeof(TokenItem));
            TokenItem name = (TokenItem)d.Children[0];

            Assert.AreEqual(CssTokenType.Identifier, name.Token.TokenType);

            Assert.AreEqual(typeof(TokenItem), d.Children[1].GetType());
            Assert.AreEqual(CssTokenType.Colon, ((TokenItem)d.Children[1]).Token.TokenType);

            Assert.AreEqual(typeof(UrlItem), d.Children[2].GetType());
            Assert.AreEqual(3, ((UrlItem)d.Children[2]).Children.Count);

            Assert.AreEqual(typeof(NumericalValue), d.Children[3].GetType());
        }
Exemplo n.º 2
0
        public void Declaration_InvalidParse()
        {
            string[] rules = new string[]
            {
                ".foo { color: red color: blue; color: green; }",
                ".foo { : red; color: blue;  }",
                ".foo { color: (red] blue; color: green;  }",
                ".foo { color red: blue; color: green;  }",
                ".foo { *color: blue; color: green;  }",
                ".foo { **color: blue; color: green;  }",
            };

            foreach (string text in rules)
            {
                ITextProvider tp     = new StringTextProvider(text);
                TokenStream   tokens = Helpers.MakeTokenStream(tp);
                RuleSet       rs     = new RuleSet();

                Assert.IsTrue(rs.Parse(new ItemFactory(tp, tokens), tp, tokens));
                Assert.IsTrue(rs.IsValid);
                Assert.AreEqual(2, rs.Block.Declarations.Count);
                Assert.IsFalse(rs.Block.Declarations[0].IsValid);
                Assert.IsTrue(rs.Block.Declarations[1].IsValid);
            }
        }
Exemplo n.º 3
0
        public void Declaration_ParseTest_CustomPropertyValue_WithBracedBlock()
        {
            string        text   = "--paper-toolbar: { border: none; };";
            ITextProvider tp     = new StringTextProvider(text);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Declaration   d      = new Declaration();

            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsTrue(d.IsCustomProperty);

            Assert.IsFalse(d.HasParseErrors);

            Assert.AreEqual(0, d.Start);
            Assert.AreEqual(text.Length, d.AfterEnd);

            Assert.AreEqual(4, d.Children.Count);
            Assert.AreEqual(typeof(TokenItem), d.Semicolon.GetType());
            Assert.AreEqual(34, d.Semicolon.Start); // make sure we have the correct semicolon

            Assert.AreEqual(typeof(TokenItem), d.Children[0].GetType());
            Assert.AreEqual(CssTokenType.Identifier, ((TokenItem)d.Children[0]).Token.TokenType);

            Assert.AreEqual(typeof(TokenItem), d.Children[1].GetType());
            Assert.AreEqual(CssTokenType.Colon, ((TokenItem)d.Children[1]).Token.TokenType);

            Assert.IsInstanceOfType(d.Children[2], typeof(PropertyValueBlock));
            PropertyValueBlock pvb = (PropertyValueBlock)d.Children[2];

            #region Verifying property value block

            Assert.AreEqual(6, pvb.Children.Count);
            Assert.AreEqual(17, pvb.Start);
            Assert.AreEqual(34, pvb.AfterEnd);

            Assert.AreEqual(typeof(TokenItem), pvb.Children[0].GetType());
            Assert.AreEqual(CssTokenType.OpenCurlyBrace, ((TokenItem)pvb.Children[0]).TokenType);

            Assert.AreEqual(typeof(TokenItem), pvb.Children[1].GetType());
            Assert.AreEqual(CssTokenType.Identifier, ((TokenItem)pvb.Children[1]).TokenType);

            Assert.AreEqual(typeof(TokenItem), pvb.Children[2].GetType());
            Assert.AreEqual(CssTokenType.Colon, ((TokenItem)pvb.Children[2]).TokenType);

            Assert.AreEqual(typeof(TokenItem), pvb.Children[3].GetType());
            Assert.AreEqual(CssTokenType.Identifier, ((TokenItem)pvb.Children[3]).TokenType);

            Assert.AreEqual(typeof(TokenItem), pvb.Children[4].GetType());
            Assert.AreEqual(CssTokenType.Semicolon, ((TokenItem)pvb.Children[4]).TokenType);

            Assert.AreEqual(typeof(TokenItem), pvb.Children[5].GetType());
            Assert.AreEqual(CssTokenType.CloseCurlyBrace, ((TokenItem)pvb.Children[5]).TokenType);

            #endregion

            Assert.AreEqual(typeof(TokenItem), d.Children[d.Children.Count - 1].GetType());
            Assert.AreEqual(CssTokenType.Semicolon, ((TokenItem)d.Children[d.Children.Count - 1]).Token.TokenType);

            Assert.AreEqual(1, d.Values.Count);
            Assert.AreEqual(d.Children[2], d.Values[0]);
        }
Exemplo n.º 4
0
        public void Declaration_ParseTest_CustomPropertyName()
        {
            string        text   = "--color: blue;";
            ITextProvider tp     = new StringTextProvider(text);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Declaration   d      = new Declaration();

            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsTrue(d.IsCustomProperty);

            Assert.AreEqual(0, d.Start);
            Assert.AreEqual(text.Length, d.AfterEnd);

            Assert.AreEqual(4, d.Children.Count);
            Assert.AreEqual(typeof(TokenItem), d.Semicolon.GetType());

            Assert.AreEqual(typeof(TokenItem), d.Children[0].GetType());
            Assert.AreEqual(CssTokenType.Identifier, ((TokenItem)d.Children[0]).Token.TokenType);

            Assert.AreEqual(typeof(TokenItem), d.Children[1].GetType());
            Assert.AreEqual(CssTokenType.Colon, ((TokenItem)d.Children[1]).Token.TokenType);

            Assert.AreEqual(typeof(TokenItem), d.Children[2].GetType());
            Assert.AreEqual(CssTokenType.Identifier, ((TokenItem)d.Children[2]).Token.TokenType);

            Assert.AreEqual(typeof(TokenItem), d.Children[d.Children.Count - 1].GetType());
            Assert.AreEqual(CssTokenType.Semicolon, ((TokenItem)d.Children[d.Children.Count - 1]).Token.TokenType);

            Assert.AreEqual(1, d.Values.Count);
            Assert.AreEqual(d.Children[2], d.Values[0]);
        }
Exemplo n.º 5
0
        public void FontFaceRule_ParseTest()
        {
            string            text   = "@font-face {  font-family: Headline; src: local(Futura-Medium), url(fonts.svg#MyGeometricModern) format(\"svg\", 'opentype'); unicode-range: U+3000-9FFF, U+ff??; }";
            ITextProvider     tp     = new StringTextProvider(text);
            TokenStream       tokens = Helpers.MakeTokenStream(tp);
            FontFaceDirective ff     = new FontFaceDirective();

            Assert.IsTrue(ff.Parse(new ItemFactory(tp, null), tp, tokens));

            Assert.IsTrue(tp.CompareTo(ff.Keyword.Start, "font-face", ignoreCase: false));
            Assert.IsNotNull(ff.Block.OpenCurlyBrace);
            Assert.IsNotNull(ff.Block.CloseCurlyBrace);

            Assert.AreEqual(3, ff.RuleBlock.Declarations.Count);

            Assert.IsTrue(tp.CompareTo(ff.RuleBlock.Declarations[0].PropertyName.Start, "font-family", ignoreCase: false));

            Assert.IsTrue(tp.CompareTo(ff.RuleBlock.Declarations[1].PropertyName.Start, "src", ignoreCase: false));
            Assert.IsTrue(ff.RuleBlock.Declarations[1].Values[0] is FunctionLocal);
            Assert.IsTrue(ff.RuleBlock.Declarations[1].Values[2] is UrlItem);
            Assert.IsTrue(ff.RuleBlock.Declarations[1].Values[3] is FunctionFormat);
            FunctionFormat func = ff.RuleBlock.Declarations[1].Values[3] as FunctionFormat;

            FunctionArgument arg = func.Arguments[0] as FunctionArgument;

            Assert.AreEqual("\"svg\",", tp.GetText(arg.Start, arg.Length));

            arg = func.Arguments[1] as FunctionArgument;
            Assert.AreEqual("'opentype'", tp.GetText(arg.Start, arg.Length));

            Assert.IsTrue(tp.CompareTo(ff.RuleBlock.Declarations[2].PropertyName.Start, "unicode-range", ignoreCase: false));
        }
Exemplo n.º 6
0
        public void IdSelector_ParseInvalid()
        {
            string[] tests = new string[]
            {
                "#",
                "# ",
                "#*+1>",
                "#{+|}",
                "+",
                "{+|}",
                "123",
                "abc",
            };

            foreach (string test in tests)
            {
                ITextProvider tp     = new StringTextProvider(test);
                TokenStream   tokens = Helpers.MakeTokenStream(tp);
                IdSelector    s      = new IdSelector();

                if (test[0] == '#')
                {
                    Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, tokens));
                    Assert.IsFalse(s.HasParseErrors);
                    Assert.IsTrue(s.HashName.HasParseErrors);
                }
                else
                {
                    Assert.IsFalse(s.Parse(new ItemFactory(tp, null), tp, tokens));
                }
            }
        }
Exemplo n.º 7
0
        public void ItemName_ParseValid()
        {
            string[] tests = new string[]
            {
                "|",
                "*",
                "**",
                "*|",
                "*|*",
                "foo",
                "foo|",
                "foo|bar",
                "foo|bar",
                "foo|*",
                "*foo",
            };

            foreach (string test in tests)
            {
                ITextProvider tp     = new StringTextProvider(test);
                TokenStream   tokens = Helpers.MakeTokenStream(tp);
                ItemName      s      = new ItemName();
                Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, tokens));
            }
        }
        public void SimpleSelector_Invalid()
        {
            string[] tests = new string[]
            {
                "||{}",
                "**{}",
                "h2..foo{}",
                ":",
                "::",
                ":::",
                ".",
                "..",
                ".#:foo",
                "#",
                "##",
                "#:foo",
                "!!ul > li",
                "ul!! > li",
                "!ul! > li",
                "a.external:not(::::)",
                "a.external:not(.#)",
                "|| foo",
            };

            foreach (string test in tests)
            {
                ITextProvider  tp = new StringTextProvider(test);
                TokenStream    ts = Helpers.MakeTokenStream(tp);
                SimpleSelector s  = new SimpleSelector();
                Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, ts));
                Assert.IsFalse(s.IsValid);
            }
        }
Exemplo n.º 9
0
        public void CssTextRange_CompareDecoded()
        {
            for (int i = 0; i < 2; i++)
            {
#if !SUPPORT_ENCODED_CSS
                if (i == 0)
                {
                    continue;
                }
#endif
                // Try the same string with and without encoded/escaped chars
                string text = (i == 0)
                    ? @"@na\mes\70 ace \66 \o\o 'www.\'f\6F \o\'.com';"
                    : @"@namespace foo 'www.\'foo\'.com'";

                ITextProvider tp     = new StringTextProvider(text);
                TokenList     tokens = Helpers.MakeTokens(tp);

                Assert.AreEqual("@", TextRange.GetDecodedText(tokens[0].Start, tokens[0].Length, tp, forStringToken: false));
                Assert.AreEqual("namespace", TextRange.GetDecodedText(tokens[1].Start, tokens[1].Length, tp, forStringToken: false));
                Assert.AreEqual("foo", TextRange.GetDecodedText(tokens[2].Start, tokens[2].Length, tp, forStringToken: false));
                Assert.AreEqual(@"'www.'foo'.com'", TextRange.GetDecodedText(tokens[3].Start, tokens[3].Length, tp, forStringToken: false));

                Assert.IsTrue(TextRange.CompareDecoded(tokens[1].Start, tokens[1].Length, tp, "namespace", ignoreCase: false));
                Assert.IsFalse(TextRange.CompareDecoded(tokens[1].Start, tokens[1].Length, tp, "NAMEspace", ignoreCase: false));
                Assert.IsTrue(TextRange.CompareDecoded(tokens[1].Start, tokens[1].Length, tp, "NAMEspace", ignoreCase: true));
                Assert.IsFalse(TextRange.CompareDecoded(tokens[1].Start, tokens[1].Length, tp, "namespace-foobar", ignoreCase: true));
                Assert.IsFalse(TextRange.CompareDecoded(tokens[1].Start, tokens[1].Length, tp, "@namespace", ignoreCase: true));
                Assert.IsTrue(TextRange.CompareDecoded(tokens[2].Start, tokens[2].Length, tp, "foo", ignoreCase: false));

#if SUPPORT_ENCODED_CSS
                Assert.IsTrue(TextRange.CompareDecoded(tokens[3].Start, tokens[3].Length, tp, "'www.'FOO'.com'", ignoreCase: true));
#endif
            }
        }
Exemplo n.º 10
0
        public void Combinator6SelectorTest()
        {
            string        text = "A+B C >     D * foo {}";
            ITextProvider tp   = new StringTextProvider(text);
            TokenStream   ts   = Helpers.MakeTokenStream(tp);

            Selector s = new Selector();

            Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, ts), "Valid CSS '{0}' parsed incorrectly", text);

            Assert.AreEqual(s.SimpleSelectors.Count, 6, "We should have only 6 SimpleSelectors for CSS '{0}'", text);

            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[0].Name.Start, "A", ignoreCase: false));
            Assert.IsNotNull(s.SimpleSelectors[0].SelectorCombineOperator);
            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[0].SelectorCombineOperator.Start, "+", ignoreCase: false));

            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[1].Name.Start, "B", ignoreCase: false));
            Assert.IsNull(s.SimpleSelectors[1].SelectorCombineOperator);

            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[2].Name.Start, "C", ignoreCase: false), "SimpleSelector C not obtained for CSS '{0}'", text);
            Assert.IsNotNull(s.SimpleSelectors[2].SelectorCombineOperator);
            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[2].SelectorCombineOperator.Start, ">", ignoreCase: false), "SelectorCombineOperator \">\" not obtained for CSS '{0}'", text);

            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[3].Name.Start, "D", ignoreCase: false), "SimpleSelector D not obtained for CSS '{0}'", text);
            Assert.IsNull(s.SimpleSelectors[3].SelectorCombineOperator);

            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[4].Name.Start, "*", ignoreCase: false));
            Assert.IsNull(s.SimpleSelectors[4].SelectorCombineOperator);

            Assert.IsTrue(tp.CompareTo(s.SimpleSelectors[5].Name.Start, "foo", ignoreCase: false));
            Assert.IsNull(s.SimpleSelectors[5].SelectorCombineOperator);

            Assert.IsTrue(s.IsValid);
        }
Exemplo n.º 11
0
        public void CssTextRange_Simple()
        {
            ITextProvider textProvider = new StringTextProvider("01234567890123456789");

            Assert.AreEqual("01234", textProvider.GetText(10, 5));

            Assert.IsFalse(TextRange.Touches(10, 5, -1));
            Assert.IsFalse(TextRange.Touches(10, 5, 9));
            Assert.IsTrue(TextRange.Touches(10, 5, 10));
            Assert.IsTrue(TextRange.Touches(10, 5, 14));
            Assert.IsTrue(TextRange.Touches(10, 5, 15));
            Assert.IsFalse(TextRange.Touches(10, 5, 16));
            Assert.IsFalse(TextRange.Touches(10, 5, 100));

            Assert.IsFalse(TextRange.ContainsChar(10, 5, -1));
            Assert.IsFalse(TextRange.ContainsChar(10, 5, 9));
            Assert.IsTrue(TextRange.ContainsChar(10, 5, 10));
            Assert.IsTrue(TextRange.ContainsChar(10, 5, 14));
            Assert.IsFalse(TextRange.ContainsChar(10, 5, 15));
            Assert.IsFalse(TextRange.ContainsChar(10, 5, 16));
            Assert.IsFalse(TextRange.ContainsChar(10, 5, 100));

            Assert.IsFalse(TextRange.Intersects(10, 5, 0, 10));
            Assert.IsTrue(TextRange.Intersects(10, 5, 0, 11));
            Assert.IsFalse(TextRange.Intersects(10, 5, 10, 0));
            Assert.IsTrue(TextRange.Intersects(10, 5, 10, 1));
            Assert.IsTrue(TextRange.Intersects(10, 5, 11, 10));
            Assert.IsTrue(TextRange.Intersects(10, 5, 14, 1));
            Assert.IsTrue(TextRange.Intersects(10, 5, 14, 10));
            Assert.IsFalse(TextRange.Intersects(10, 5, 15, 0));
            Assert.IsFalse(TextRange.Intersects(10, 5, 15, 1));
            Assert.IsFalse(TextRange.Intersects(10, 5, 20, 10));
        }
        public void ClassSelector_ParseTest()
        {
            string        text1  = ".a";
            ITextProvider tp     = new StringTextProvider(text1);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            ClassSelector d      = new ClassSelector();

            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(d.ClassName);
            Assert.IsNotNull(d.Dot);

            text1  = ". a";
            tp     = new StringTextProvider(text1);
            tokens = Helpers.MakeTokenStream(tp);
            d      = new ClassSelector();
            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNull(d.ClassName);
            Assert.IsNotNull(d.Dot);

            text1  = "a";
            tp     = new StringTextProvider(text1);
            tokens = Helpers.MakeTokenStream(tp);
            d      = new ClassSelector();
            Assert.IsFalse(d.Parse(new ItemFactory(tp, null), tp, tokens));

            text1  = ".a[b=c]";
            tp     = new StringTextProvider(text1);
            tokens = Helpers.MakeTokenStream(tp);
            d      = new ClassSelector();
            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(d.ClassName);
            Assert.IsNotNull(d.Dot);
        }
Exemplo n.º 13
0
        public void FunctionRgb_ParseTest1()
        {
            ITextProvider tp     = new StringTextProvider("rgb(25, 10%, 34)");
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Function      f      = Function.ParseFunction(null, new ItemFactory(tp, null), tp, tokens);

            Assert.AreEqual(typeof(FunctionColor), f.GetType());
            Assert.AreEqual(3, f.Arguments.Count);

            Assert.IsInstanceOfType(f.Arguments[0], typeof(FunctionArgument));
            FunctionArgument fa = f.Arguments[0] as FunctionArgument;

            Assert.IsNotNull(fa.Comma);

            Assert.AreEqual(1, fa.ArgumentItems.Count);
            Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue));
            NumericalValue numericalValue = (NumericalValue)fa.ArgumentItems[0];

            Assert.IsInstanceOfType(numericalValue.Children[0], typeof(TokenItem));
            Assert.AreEqual(CssTokenType.Number, ((TokenItem)numericalValue.Children[0]).TokenType);

            Assert.IsInstanceOfType(f.Arguments[1], typeof(FunctionArgument));
            Assert.IsNotNull(fa.Comma);
            Assert.AreEqual(1, fa.ArgumentItems.Count);
            Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue));

            fa = f.Arguments[1] as FunctionArgument;
            Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue));
            numericalValue = (NumericalValue)fa.ArgumentItems[0];
            Assert.IsInstanceOfType(numericalValue.Children[1], typeof(TokenItem));
            Assert.IsInstanceOfType(numericalValue.Children[1], typeof(TokenItem));
            Assert.AreEqual(CssTokenType.Number, ((TokenItem)numericalValue.Children[0]).TokenType);
            Assert.AreEqual(CssTokenType.Units, ((TokenItem)numericalValue.Children[1]).TokenType);
        }
Exemplo n.º 14
0
        public void Combinator2SelectorTest()
        {
            string[] tests = new string[]
            {
                "foo bar {}",
                "foo                bar{}",
                "foo    bar {}",
                "foo > bar{}",
                "foo~bar{}",
                "foo ~ bar{}",
                "foo + bar {}",
                "foo + bar {}    ",
                "foo h1.bar {}",
                "c1.foo                bar{}",
                "c1#foo    bar {}",
                "foo > h1.bar{}",
                "h2.foo ~ bar{}",
                "foo + h1.bar {}",
                "h2.foo + bar {}    ",
            };

            foreach (string test in tests)
            {
                ITextProvider tp = new StringTextProvider(test);
                TokenStream   ts = Helpers.MakeTokenStream(tp);
                Selector      s  = new Selector();

                Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, ts), "Valid CSS '{0}' parsed incorrectly", test);
                Assert.IsTrue(s.IsValid);
                Assert.AreEqual(s.SimpleSelectors.Count, 2, "We should have only 2 SimpleSelectors for CSS '{0}'", test);
            }
        }
Exemplo n.º 15
0
        public void AtDirective_Parse()
        {
            string text =
                @"@keyframes { foo } " +
                @"@-ms-keyframes { foo } " +
                @"@-moz-keyframes { foo } " +
                @"@-webkit-keyframes { foo } " +
                @"@keyframes foo { from, to { top: 50% } 0% { left: 100px } } " +
                @"@font-face { } " +
                @"@variables { foo: bar } " +
                @"@page { @top-left-corner { foo } }" +
                @"@counter { list-style-type: decimal; }" +
                @"@ ";

            StyleSheet    ss = new StyleSheet();
            ITextProvider tp = new StringTextProvider(text);

            Assert.IsTrue(ss.Parse(new ItemFactory(tp, null), tp, Helpers.MakeTokenStream(tp)));

            Assert.IsInstanceOfType(ss.Children[0], typeof(KeyFramesDirective));
            Assert.IsInstanceOfType(ss.Children[1], typeof(KeyFramesDirective));
            Assert.IsInstanceOfType(ss.Children[2], typeof(KeyFramesDirective));
            Assert.IsInstanceOfType(ss.Children[3], typeof(KeyFramesDirective));
            Assert.IsInstanceOfType(ss.Children[4], typeof(KeyFramesDirective));
            Assert.IsInstanceOfType(ss.Children[5], typeof(FontFaceDirective));
            Assert.IsInstanceOfType(ss.Children[6], typeof(UnknownDirective));
            Assert.IsInstanceOfType(ss.Children[7], typeof(PageDirective));
            Assert.IsInstanceOfType(ss.Children[8], typeof(CounterDirective));
        }
Exemplo n.º 16
0
        public void ItemName_ParseTest()
        {
            string        text1  = "a|b";
            ITextProvider tp     = new StringTextProvider(text1);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            ItemName      n      = new ItemName();

            Assert.IsTrue(n.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(n.Name);
            Assert.IsNotNull(n.Namespace);
            Assert.IsNotNull(n.Separator);

            text1  = "|b";
            tp     = new StringTextProvider(text1);
            tokens = Helpers.MakeTokenStream(tp);
            n      = new ItemName();
            Assert.IsTrue(n.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(n.Name);
            Assert.IsNull(n.Namespace);
            Assert.IsNotNull(n.Separator);

            text1  = "*|b";
            tp     = new StringTextProvider(text1);
            tokens = Helpers.MakeTokenStream(tp);
            n      = new ItemName();
            Assert.IsTrue(n.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(n.Name);
            Assert.IsNotNull(n.Namespace);
            Assert.IsNotNull(n.Separator);
        }
        public void ImportDirective_ParseTest()
        {
            ITextProvider    tp     = new StringTextProvider("@import 'foo';");
            TokenStream      tokens = Helpers.MakeTokenStream(tp);
            CharsetDirective d      = new CharsetDirective();

            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(d.CharacterSet);
            Assert.IsTrue(tp.CompareTo(d.CharacterSet.Start, "'foo'", ignoreCase: false));
            Assert.IsNotNull(d.Keyword);
            Assert.IsNotNull(d.Semicolon);

            tp     = new StringTextProvider("@import ;");
            tokens = Helpers.MakeTokenStream(tp);
            d      = new CharsetDirective();
            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(d.Keyword);
            Assert.IsNull(d.CharacterSet);
            Assert.IsNotNull(d.Semicolon);

            tp     = new StringTextProvider("@import");
            tokens = Helpers.MakeTokenStream(tp);
            d      = new CharsetDirective();
            Assert.IsTrue(d.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsNotNull(d.Keyword);
            Assert.IsNull(d.CharacterSet);
            Assert.IsNull(d.Semicolon);
        }
        public void IncrementalParse_SimpleChangeTest()
        {
            CssTree       doc   = new CssTree(new DefaultParserFactory());
            ITextProvider text1 = new StringTextProvider(".foo { color: red } .bar { /* comment */ color: rgb(100 }");

            doc.TextProvider = text1;

            bool fullTreeUpdateFired = false;
            CssItemsChangedEventArgs changeEventArgs = null;

            doc.TreeUpdated += (object sender, CssTreeUpdateEventArgs eventArgs) =>
            {
                fullTreeUpdateFired = true;
            };

            doc.ItemsChanged += (object sender, CssItemsChangedEventArgs eventArgs) =>
            {
                changeEventArgs = eventArgs;
            };

            ITextProvider text2 = new StringTextProvider(".foo { color: BLUE; } .bar { /* comment */ color: rgb(100 }");

            doc.OnTextChange(text2, 14, 3, 5);

            Assert.IsFalse(fullTreeUpdateFired);
            Assert.IsNotNull(changeEventArgs);
            Assert.AreEqual(1, changeEventArgs.DeletedItems.Count);
            Assert.AreEqual(1, changeEventArgs.InsertedItems.Count);

            Declaration oldDecl = changeEventArgs.DeletedItems[0] as Declaration;
            Declaration newDecl = changeEventArgs.InsertedItems[0] as Declaration;

            Assert.AreEqual("color: red", text1.GetText(oldDecl.Start, oldDecl.Length));
            Assert.AreEqual("color: BLUE;", text2.GetText(newDecl.Start, newDecl.Length));
        }
Exemplo n.º 19
0
        public void ParseUnknownTest()
        {
            string        text = "}";
            ITextProvider tp   = new StringTextProvider(text);
            {
                ParseItem pi = UnknownItem.ParseUnknown(
                    null, new ItemFactory(tp, null), tp,
                    Helpers.MakeTokenStream(tp),
                    ParseErrorType.OpenCurlyBraceMissingForRule);

                Assert.IsNotNull(pi);
                Assert.IsTrue(pi.HasParseErrors);
                Assert.AreEqual(ParseErrorType.OpenCurlyBraceMissingForRule, pi.ParseErrors[0].ErrorType);
                Assert.AreEqual(ParseErrorLocation.WholeItem, pi.ParseErrors[0].Location);
            }

            // Try a URL
            {
                text = "url('foo.jpg')";
                tp   = new StringTextProvider(text);

                UrlItem pi = UnknownItem.ParseUnknown(
                    null, new ItemFactory(tp, null), tp,
                    Helpers.MakeTokenStream(tp)) as UrlItem;

                Assert.IsNotNull(pi);
            }
        }
        public void NamespaceDirective_ParseTest()
        {
            TokenStream   ts;
            string        text = "@namespace foo \"www.foo.com\";";
            ITextProvider tp   = new StringTextProvider(text);

            ts = Helpers.MakeTokenStream(tp);
            NamespaceDirective pd = new NamespaceDirective();

            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace foo;";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace foo";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace;";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace { }";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace 'www.microsoft.com'";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace foo bar;";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));

            text = "@namespace foo url('www.microsoft.com');";
            tp   = new StringTextProvider(text);
            ts   = Helpers.MakeTokenStream(tp);
            pd   = new NamespaceDirective();
            Assert.IsTrue(pd.Parse(new ItemFactory(tp, null), tp, ts));
        }
Exemplo n.º 21
0
            public InMemoryTextScope(FileInfo source)
            {
                using (var stream = source.OpenRead())
                    using (var reader = new StreamReader(stream, true))
                        FileText = reader.ReadToEnd();

                Text = new StringTextProvider(FileText);
            }
Exemplo n.º 22
0
            public InMemoryTextScope(FileInfo source)
            {
                using (var stream = source.OpenRead())
                using (var reader = new StreamReader(stream, true))
                    FileText = reader.ReadToEnd();

                Text = new StringTextProvider(FileText);
            }
Exemplo n.º 23
0
        public void FunctionAttr_Test()
        {
            ITextProvider tp     = new StringTextProvider("attr(class)");
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Function      f      = Function.ParseFunction(null, new ItemFactory(tp, null), tp, tokens);

            Assert.AreEqual(typeof(FunctionAttr), f.GetType());
        }
Exemplo n.º 24
0
        public void Function_ParseTest5()
        {
            ITextProvider tp     = new StringTextProvider("foo(a,}");
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Function      f      = Function.ParseFunction(null, new ItemFactory(tp, null), tp, tokens);

            Assert.AreEqual(typeof(Function), f.GetType());
            Assert.AreEqual("foo(", tp.GetText(f.FunctionName.Start, f.FunctionName.Length));
        }
Exemplo n.º 25
0
        public void CssTextRange_Equals()
        {
            ITextProvider tp     = new StringTextProvider("@namespace foo \"www.foo.com\";");
            TokenList     tokens = Helpers.MakeTokens(tp);

            Assert.IsTrue(tp.CompareTo(tokens[0].Start, "@", ignoreCase: false));
            Assert.IsTrue(tp.CompareTo(tokens[1].Start, "Namespace", ignoreCase: true));
            Assert.IsTrue(tp.CompareTo(tokens[2].Start, "foo", ignoreCase: false));
        }
        public void UnknownDirective_ParseTest()
        {
            string           text = "@foo \"bar\";";
            ITextProvider    tp   = new StringTextProvider(text);
            UnknownDirective ud   = new UnknownDirective();

            Assert.IsTrue(ud.Parse(new ItemFactory(tp, null), tp, Helpers.MakeTokenStream(tp)));
            Assert.AreEqual("@", text.Substring(ud.At.Start, ud.At.Length));
            Assert.AreEqual("foo", text.Substring(ud.Keyword.Start, ud.Keyword.Length));
        }
Exemplo n.º 27
0
        public void Ruleset_ParseTest()
        {
            RuleSet       target = new RuleSet();
            string        text   = ".a { }";
            ITextProvider tp     = new StringTextProvider(text);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            bool          actual = target.Parse(new ItemFactory(tp, null), tp, tokens);

            Assert.AreEqual(true, actual);
        }
Exemplo n.º 28
0
        public void ParseTest()
        {
            string[] samples1 = new string[]
            {
                "100px",
                "200%",
                "-3grad",
                "0.8em",
                "-0.5deg",
                "22s",
                "345.7Hz",
                "144dpi",
                "12dppx",
                "12st",
                "0.7vmin",
                "0vmax",
                "1.117gr",
                "-6.0dB",
                "+12dB",
            };

            UnitType[] types1 = new UnitType[]
            {
                UnitType.Length,
                UnitType.Percentage,
                UnitType.Angle,
                UnitType.Length,
                UnitType.Angle,
                UnitType.Time,
                UnitType.Frequency,
                UnitType.Resolution,
                UnitType.Resolution,
                UnitType.Semitones,
                UnitType.Viewport,
                UnitType.Viewport,
                UnitType.Grid,
                UnitType.Volume,
                UnitType.Volume,
            };

            int i = 0;

            foreach (string text in samples1)
            {
                ITextProvider tp     = new StringTextProvider(text);
                TokenStream   tokens = Helpers.MakeTokenStream(tp);
                tokens.Advance(1);

                UnitValue uv = new UnitValue();
                uv.Parse(new ItemFactory(tp, null), tp, tokens);

                Assert.AreEqual(types1[i++], uv.UnitType);
                Assert.AreEqual(CssTokenType.Units, uv.UnitToken.TokenType);
            }
        }
        public void KeyFramesRule_ParseTest()
        {
            string text =
                @"@keyframes bounce {
                      from {
                          top: 100px;
                          animation-timing-function: ease-out;
                      }
                      25% {
                          top: 50px;
                          animation-timing-function: ease-in;
                      }
                      50% {
                          top: 100px;
                          animation-timing-function: ease-out;
                      }
                      75% {
                          top: 75px;
                          animation-timing-function: ease-in;
                      }
                      to {
                          top: 100px;
                      }
                }";

            ITextProvider      tp     = new StringTextProvider(text);
            TokenStream        tokens = Helpers.MakeTokenStream(tp);
            KeyFramesDirective kf     = new KeyFramesDirective();

            Assert.IsTrue(kf.Parse(new ItemFactory(tp, null), tp, tokens));
            Assert.IsTrue(tp.CompareTo(kf.Keyword.Start, "keyframes", ignoreCase: false));
            Assert.IsTrue(tp.CompareTo(kf.Name.Start, "bounce", ignoreCase: false));
            Assert.IsNotNull(kf.Block.OpenCurlyBrace);
            Assert.IsNotNull(kf.Block.CloseCurlyBrace);

            KeyFrameSelectorType[] types = new KeyFrameSelectorType[]
            {
                KeyFrameSelectorType.From,
                KeyFrameSelectorType.Percentage,
                KeyFrameSelectorType.Percentage,
                KeyFrameSelectorType.Percentage,
                KeyFrameSelectorType.To
            };

            Assert.AreEqual(5, kf.KeyFramesBlock.KeyFrames.Count);
            for (int i = 0; i < kf.KeyFramesBlock.KeyFrames.Count; i++)
            {
                Assert.AreEqual(types[i], kf.KeyFramesBlock.KeyFrames[i].Selectors[0].SelectorType);
                Assert.IsNotNull(kf.KeyFramesBlock.KeyFrames[i].RuleBlock.OpenCurlyBrace);
                Assert.IsNotNull(kf.KeyFramesBlock.KeyFrames[i].RuleBlock.CloseCurlyBrace);
                Assert.IsTrue(kf.KeyFramesBlock.KeyFrames[i].RuleBlock.Declarations.Count > 0);
                Assert.IsTrue(tp.CompareTo(kf.KeyFramesBlock.KeyFrames[i].RuleBlock.Declarations[0].PropertyName.Start, "top", ignoreCase: false));
            }
        }
Exemplo n.º 30
0
        public void FunctionExpression_Test()
        {
            ITextProvider tp = new StringTextProvider(
                "expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? document.documentElement.scrollTop : document.body.scrollTop)");

            TokenStream tokens = Helpers.MakeTokenStream(tp);
            Function    f      = Function.ParseFunction(null, new ItemFactory(tp, null), tp, tokens);

            Assert.AreEqual(typeof(FunctionExpression), f.GetType());
            Assert.AreEqual(tp.Length, f.Length);
        }
        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);
        }