Beispiel #1
0
        public void ParseDeclerationBlockTest()
        {
            const string CssTestStr = @"@charset ""UTF-8"";
/*! Hello World this is a CSS comment */
html {
  font-family: sans-serif;
        }

";

            // Tokenize a CSS string and make sure it spits out the correct token sequence
            CssToken[] Actual   = CssTokenizer.Parse(CssTestStr);
            CssToken[] Expected = new CssToken[] { new AtToken("charset"), WhitespaceToken.Space, new StringToken("UTF-8"), SemicolonToken.Instance, WhitespaceToken.LFLF,
                                                   WhitespaceToken.LFLF,
                                                   new IdentToken("html"), WhitespaceToken.Space, BracketOpenToken.Instance, WhitespaceToken.LFLF,
                                                   new IdentToken("font-family"), ColonToken.Instance, WhitespaceToken.Space, new IdentToken("sans-serif"), SemicolonToken.Instance, WhitespaceToken.LFLF,
                                                   BracketCloseToken.Instance, WhitespaceToken.LFLF, EOFToken.Instance };

            var Engine = new Difference.DiffEngine <CssToken>();
            var diff   = Engine.Compile(Expected, Actual);

            if (diff.Count > 1)
            {
                Engine.DisplayHTML(diff);
            }

            Assert.Equal(Expected, Actual);
        }
Beispiel #2
0
        public void ParseComplexTest()
        {
            const string CssTestStr = @"input[type=""checkbox""].filter-class-cb:checked + label.filter-class-lb, input[type=""checkbox""].filter-class-cb:active + label.filter-class-lb {}";

            // Tokenize a CSS string and make sure it spits out the correct token sequence
            CssToken[] Actual   = CssTokenizer.Parse(CssTestStr);
            CssToken[] Expected = new CssToken[] { new IdentToken("input"), SqBracketOpenToken.Instance, new IdentToken("type"), new DelimToken('='), new StringToken("checkbox"), SqBracketCloseToken.Instance,
                                                   new DelimToken('.'), new IdentToken("filter-class-cb"), ColonToken.Instance, new IdentToken("checked"),
                                                   WhitespaceToken.Space, new DelimToken('+'), WhitespaceToken.Space,
                                                   new IdentToken("label"), new DelimToken('.'), new IdentToken("filter-class-lb"), CommaToken.Instance, WhitespaceToken.Space,
                                                   new IdentToken("input"), SqBracketOpenToken.Instance, new IdentToken("type"), new DelimToken('='), new StringToken("checkbox"), SqBracketCloseToken.Instance,
                                                   new DelimToken('.'), new IdentToken("filter-class-cb"), ColonToken.Instance, new IdentToken("active"),
                                                   WhitespaceToken.Space, new DelimToken('+'), WhitespaceToken.Space,
                                                   new IdentToken("label"), new DelimToken('.'), new IdentToken("filter-class-lb"), WhitespaceToken.Space,
                                                   BracketOpenToken.Instance, BracketCloseToken.Instance,
                                                   EOFToken.Instance };

            var Engine = new Difference.DiffEngine <CssToken>();
            var diff   = Engine.Compile(Expected, Actual);

            if (diff.Count > 1)
            {
                Engine.DisplayHTML(diff);
            }

            Assert.Equal(Expected, Actual);
        }
Beispiel #3
0
        public void ParseMutliSpecifierTest()
        {
            const string CssTestStr = @"a:active,
a:hover {
  outline: 0; }";

            // Tokenize a CSS string and make sure it spits out the correct token sequence
            CssToken[] Actual   = CssTokenizer.Parse(CssTestStr);
            CssToken[] Expected = new CssToken[] { new IdentToken("a"), ColonToken.Instance, new IdentToken("active"), CommaToken.Instance, WhitespaceToken.LFLF,
                                                   new IdentToken("a"), ColonToken.Instance, new IdentToken("hover"), WhitespaceToken.Space, BracketOpenToken.Instance, WhitespaceToken.LFLF,
                                                   new IdentToken("outline"), ColonToken.Instance, WhitespaceToken.Space, new NumberToken(ENumericTokenType.Integer, "0", 0), SemicolonToken.Instance, WhitespaceToken.Space, BracketCloseToken.Instance, EOFToken.Instance };

            var Engine = new Difference.DiffEngine <CssToken>();
            var diff   = Engine.Compile(Expected, Actual);

            if (diff.Count > 1)
            {
                Engine.DisplayHTML(diff);
            }

            Assert.Equal(Expected, Actual);
        }
Beispiel #4
0
        public void ParsePseudoTest2()
        {
            const string CssTestStr = @"input[type=""checkbox""].filter-class-cb:not(:checked) + label.filter-class-lb[data-class-idx=""0""]::after {}";

            // Tokenize a CSS string and make sure it spits out the correct token sequence
            CssToken[] Actual   = CssTokenizer.Parse(CssTestStr);
            CssToken[] Expected = new CssToken[] { new IdentToken("input"), SqBracketOpenToken.Instance, new IdentToken("type"), new DelimToken('='), new StringToken("checkbox"), SqBracketCloseToken.Instance,
                                                   new DelimToken('.'), new IdentToken("filter-class-cb"), ColonToken.Instance, new FunctionNameToken("not"), ColonToken.Instance, new IdentToken("checked"), ParenthesisCloseToken.Instance,
                                                   WhitespaceToken.Space, new DelimToken('+'), WhitespaceToken.Space,
                                                   new IdentToken("label"), new DelimToken('.'), new IdentToken("filter-class-lb"), SqBracketOpenToken.Instance, new IdentToken("data-class-idx"), new DelimToken('='), new StringToken("0"), SqBracketCloseToken.Instance,
                                                   ColonToken.Instance, ColonToken.Instance, new IdentToken("after"), WhitespaceToken.Space,
                                                   BracketOpenToken.Instance, BracketCloseToken.Instance,
                                                   EOFToken.Instance };

            var Engine = new Difference.DiffEngine <CssToken>();
            var diff   = Engine.Compile(Expected, Actual);

            if (diff.Count > 1)
            {
                Engine.DisplayHTML(diff);
            }

            Assert.Equal(Expected, Actual);
        }