public void ChainConditionalAttribute()
        {
            var grammar = new MarkupGrammar();

            string input = "<div if=\"false\">hello</div><div elseif=\"true\">world</div><else>that's all</else>";
            var nodes = grammar.Nodes(new Position(new SourceContext(input))).Value;
            var visitor0 = new SpecialNodeVisitor(new VisitorContext());
            visitor0.Accept(nodes);
            var visitor = new ConditionalAttributeVisitor(new VisitorContext());
            visitor.Accept(visitor0.Nodes);

            Assert.AreEqual(3, visitor.Nodes.Count);
            Assert.IsAssignableFrom(typeof(SpecialNode), visitor.Nodes[0]);
            Assert.IsAssignableFrom(typeof(SpecialNode), visitor.Nodes[1]);
            Assert.IsAssignableFrom(typeof(SpecialNode), visitor.Nodes[2]);

            var ifNode = (SpecialNode)visitor.Nodes[0];
            Assert.AreEqual("if", ifNode.Element.Name);

            var elseifNode = (SpecialNode)visitor.Nodes[1];
            Assert.AreEqual("elseif", elseifNode.Element.Name);

            var elseNode = (SpecialNode)visitor.Nodes[2];
            Assert.AreEqual("else", elseNode.Element.Name);
        }
Exemplo n.º 2
0
 public bool IsSparkElementNode(Node inputNode, out Node sparkNode)
 {
     var visitor = new SpecialNodeVisitor(new VisitorContext());
     visitor.Accept(inputNode);
     sparkNode = visitor.Nodes.Count > 0 ? visitor.Nodes[0] : null;
     return sparkNode != null && sparkNode is SpecialNode;
 }
Exemplo n.º 3
0
        public void UnclosedNodeThrowsCompilerException()
        {
            var nodes = ParseNodes("<div><content name='foo'><br></etc></kontent></div>");
            Assert.AreEqual(6, nodes.Count);

            var visitor = new SpecialNodeVisitor(new VisitorContext { Paint = _paint });
            visitor.Accept(nodes);
        }
Exemplo n.º 4
0
        public void MismatchedSpecialNodeThrowsCompilerException()
        {
            var nodes = ParseNodes("<div><content name='foo'><br></etc></for></div>");
            Assert.AreEqual(6, nodes.Count);

            var visitor = new SpecialNodeVisitor(new VisitorContext { Paint = _paint });
            Assert.That(() => visitor.Accept(nodes), Throws.TypeOf<CompilerException>());
        }
Exemplo n.º 5
0
        public void WellMatchedNodesWrapContent()
        {
            var nodes = ParseNodes("<div><content name='foo'><br></etc></content></div>");
            Assert.AreEqual(6, nodes.Count);

            var visitor = new SpecialNodeVisitor(new VisitorContext());
            visitor.Accept(nodes);

            Assert.AreEqual(3, visitor.Nodes.Count);
            Assert.IsAssignableFrom(typeof(SpecialNode), visitor.Nodes[1]);

            var specialNode = (SpecialNode)visitor.Nodes[1];
            Assert.AreEqual("content", specialNode.Element.Name);
            Assert.AreEqual(2, specialNode.Body.Count);
            Assert.AreEqual("br", ((ElementNode)specialNode.Body[0]).Name);
            Assert.AreEqual("etc", ((EndElementNode)specialNode.Body[1]).Name);
        }
        public void RemoveLinesBeforeSpecialNodes()
        {
            var grammar = new MarkupGrammar();
            var nodes = grammar.Nodes(Source("<p>\r\n  <test if='true'>\r\n    <span>was true</span>\r\n  </test>\r\n</p>"));
            var specialNodeVisitor = new SpecialNodeVisitor(new VisitorContext());
            specialNodeVisitor.Accept(nodes.Value);
            omit.Accept(specialNodeVisitor.Nodes);

            Assert.AreEqual(5, omit.Nodes.Count);
            Assert.IsAssignableFrom(typeof(ElementNode), omit.Nodes[0]);
            Assert.IsAssignableFrom(typeof(TextNode), omit.Nodes[1]);
            Assert.AreEqual("", ((TextNode)omit.Nodes[1]).Text);
            Assert.IsAssignableFrom(typeof(SpecialNode), omit.Nodes[2]);

            var childNodes = ((SpecialNode) omit.Nodes[2]).Body;
            Assert.AreEqual(5, childNodes.Count);
            Assert.IsAssignableFrom(typeof(TextNode), childNodes[0]);
            Assert.AreEqual("\r\n    ", ((TextNode)childNodes[0]).Text);
            Assert.IsAssignableFrom(typeof(TextNode), childNodes[4]);
            Assert.AreEqual("", ((TextNode)childNodes[4]).Text);
        }
Exemplo n.º 7
0
        public void ParseNodesShouldParseIntoMultipleNodes()
        {
            var sparkSyntax = new SparkSyntax();
            var nodes = sparkSyntax.ParseNodes("<div><use content='main'/></div>");
            var visitor = new SpecialNodeVisitor(new VisitorContext());
            visitor.Accept(nodes);

            Assert.That(visitor.Nodes.Count, Is.EqualTo(3));
            Assert.That(visitor.Nodes[0], Is.InstanceOfType(typeof(ElementNode)));
            Assert.That(visitor.Nodes[1], Is.InstanceOfType(typeof(SpecialNode)));
            Assert.That(visitor.Nodes[2], Is.InstanceOfType(typeof(EndElementNode)));
        }