Exemplo n.º 1
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.º 2
0
        public void Declaration_ParseTest_CustomPropertyValue_WithMultipleBracedBlocks()
        {
            string        text   = "--jsCode: if(condition) { trueAction(); } else { falseAction() };";
            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(7, d.Children.Count);
            Assert.AreEqual(typeof(TokenItem), d.Semicolon.GetType());
            Assert.AreEqual(64, 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(Function));
            Function ifFunction = (Function)d.Children[2];

            // asserts for: if(condition)
            {
                Assert.AreEqual(1, ifFunction.Arguments.Count);
                Assert.AreEqual("condition", tp.GetText(ifFunction.Arguments[0].Start, ifFunction.Arguments[0].Length));
            }

            Assert.IsInstanceOfType(d.Children[3], typeof(PropertyValueBlock));
            PropertyValueBlock pvb1 = (PropertyValueBlock)d.Children[3];

            // asserts for: { trueAction(); }
            {
                Assert.AreEqual(4, pvb1.Children.Count);

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

                Assert.IsInstanceOfType(pvb1.Children[1], typeof(Function));
                Assert.AreEqual(0, ((Function)pvb1.Children[1]).Arguments.Count);

                Assert.IsInstanceOfType(pvb1.Children[2], typeof(TokenItem));
                Assert.AreEqual(CssTokenType.Semicolon, ((TokenItem)pvb1.Children[2]).TokenType);

                Assert.IsInstanceOfType(pvb1.Children[3], typeof(TokenItem));
                Assert.AreEqual(CssTokenType.CloseCurlyBrace, ((TokenItem)pvb1.Children[3]).TokenType);
            }

            Assert.IsInstanceOfType(d.Children[4], typeof(TokenItem));
            Assert.AreEqual(CssTokenType.Identifier, ((TokenItem)d.Children[4]).TokenType);

            Assert.IsInstanceOfType(d.Children[5], typeof(PropertyValueBlock));
            PropertyValueBlock pvb2 = (PropertyValueBlock)d.Children[5];

            // asserts for: { falseAction() }
            // note: to differentiate between the block above, this one doesn't have a semicolon
            // after the method call
            {
                Assert.AreEqual(3, pvb2.Children.Count);

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

                Assert.IsInstanceOfType(pvb2.Children[1], typeof(Function));
                Assert.AreEqual(0, ((Function)pvb2.Children[1]).Arguments.Count);

                Assert.IsInstanceOfType(pvb2.Children[2], typeof(TokenItem));
                Assert.AreEqual(CssTokenType.CloseCurlyBrace, ((TokenItem)pvb2.Children[2]).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(4, d.Values.Count);
            Assert.AreEqual(d.Children[2], d.Values[0]);
            Assert.AreEqual(d.Children[3], d.Values[1]);
            Assert.AreEqual(d.Children[4], d.Values[2]);
            Assert.AreEqual(d.Children[5], d.Values[3]);
        }