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);
        }
Beispiel #2
0
        public void ParseItem_AddParseErrorTest()
        {
            CharsetDirective cd = new CharsetDirective();

            Assert.IsFalse(cd.HasParseErrors);
            Assert.IsFalse(cd.ContainsParseErrors);
            Assert.AreEqual(0, cd.ParseErrors.Count);

            cd.Children.AddParseError(ParseErrorType.AtDirectiveSemicolonMissing);
            Assert.IsTrue(cd.HasParseErrors);
            Assert.IsTrue(cd.ContainsParseErrors);
            Assert.AreEqual(1, cd.ParseErrors.Count);
            Assert.AreEqual(ParseErrorType.AtDirectiveSemicolonMissing, cd.ParseErrors[0].ErrorType);
            Assert.AreEqual(ParseErrorLocation.BeforeItem, cd.ParseErrors[0].Location);

            cd.AddParseError(ParseErrorType.UnexpectedToken, ParseErrorLocation.WholeItem);
            Assert.AreEqual(2, cd.ParseErrors.Count);
            Assert.AreEqual(ParseErrorType.UnexpectedToken, cd.ParseErrors[1].ErrorType);
            Assert.AreEqual(ParseErrorLocation.WholeItem, cd.ParseErrors[1].Location);

            TokenItem ti = new TokenItem(new CssToken(CssTokenType.At, 0, 0), null);

            Assert.IsFalse(ti.HasParseErrors);
            Assert.AreEqual(0, ti.ParseErrors.Count);

            cd.Children.Add(ti);
            cd.Children.AddParseError(ParseErrorType.AtDirectiveNameMissing);
            Assert.AreEqual(2, cd.ParseErrors.Count);
            Assert.AreEqual(1, ti.ParseErrors.Count);
            Assert.AreEqual(ParseErrorType.AtDirectiveNameMissing, ti.ParseErrors[0].ErrorType);
            Assert.AreEqual(ParseErrorLocation.AfterItem, ti.ParseErrors[0].Location);
        }
Beispiel #3
0
        public void ComplexItem_InsertCommentsTest()
        {
            string        text         = "@charset \"foo\"/* c1 */; .a { } .b { /* c2 */ }        /* c3 */";
            ITextProvider textProvider = new StringTextProvider(text);

            TokenList tokens         = Helpers.MakeTokens(text);
            TokenList filteredTokens = new TokenList();

            CssParser       parser   = new CssParser();
            IList <Comment> comments = parser.ExtractComments(textProvider, tokens, 0, tokens.Count);

            foreach (CssToken token in tokens)
            {
                if (!token.IsComment)
                {
                    filteredTokens.Add(token);
                }
            }

            StyleSheet s = parser.Parse(textProvider, filteredTokens, insertComments: false);

            Assert.AreEqual(3, s.Children.Count);
            Assert.AreEqual(3, comments.Count);

            foreach (ParseItem comment in comments)
            {
                s.InsertChildIntoSubtree(comment);
            }

            Assert.AreEqual(4, s.Children.Count);
            Assert.IsTrue(s.Children[s.Children.Count - 1] is CComment);

            CharsetDirective cd = s.Children[0] as CharsetDirective;

            Assert.AreEqual(5, cd.Children.Count);
            Assert.IsTrue(cd.Children[3] is CComment);

            RuleSet   rs = s.Children[2] as RuleSet;
            RuleBlock rb = rs.Block;

            Assert.AreEqual(3, rb.Children.Count);
            Assert.IsTrue(rb.Children[1] is CComment);
        }