Inheritance: ICloneable
Ejemplo n.º 1
0
        public void test()
        {
            loadInParser("include_1.jade");

            tagNode = (TagNode) root.pollNode();
            Assert.AreEqual(tagNode.getName(), ("p"));
            textNode = (TextNode) tagNode.getTextNode();
            Assert.AreEqual(textNode.getValue(), ("Before Include"));

            includeNode = (BlockNode) root.pollNode();
            tagNode = (TagNode) includeNode.pollNode();
            Assert.AreEqual(tagNode.getName(), ("span"));
            textNode = (TextNode) tagNode.getTextNode();
            Assert.AreEqual(textNode.getValue(), ("Hello Include"));

            yieldNode = (BlockNode) includeNode.pollNode();
            Assert.IsNotNull(yieldNode);

            /*var blockNode = (BlockNode) yieldNode.pollNode();
            tagNode = (TagNode)blockNode.pollNode();
            Assert.AreEqual(blockNode.getName(), ("p"));
            textNode = (TextNode) tagNode.getTextNode();
            Assert.AreEqual(textNode.getValue(), ("After Include"));

            Assert.AreEqual(yieldNode.hasNodes(), (false));
            Assert.AreEqual(includeNode.hasNodes(), (false));
            Assert.AreEqual(root.hasNodes(), (false));
            */
        }
        public void test()
        {
            loadInParser("large_body_text_without_pipes.jade");
            tagNode = (TagNode) root.pollNode();
            Assert.AreEqual(tagNode.getName(), ("p"));

            textNode = (TextNode) tagNode.getTextNode();
            Assert.IsNotNull(textNode.getValue());
            Assert.AreEqual(textNode.getValue(), ("Hello World!\nHere comes the Message!"));
            Assert.AreEqual(textNode.hasNodes(), (false));

            tagNode = (TagNode) root.pollNode();
            Assert.AreEqual(tagNode.getName(), ("div"));
            block = tagNode.getBlock();
            Assert.IsNotNull(block);

            tagNode = (TagNode) block.pollNode();
            Assert.AreEqual(tagNode.getName(), ("h1"));

            textNode = (TextNode) tagNode.getTextNode();
            Assert.IsNotNull(textNode.getValue());
            Assert.AreEqual(textNode.getValue(), ("Hello World!\nHere comes the second Message!"));
            Assert.AreEqual(textNode.hasNodes(), (false));

            tagNode = (TagNode) block.pollNode();
            Assert.AreEqual(tagNode.getName(), ("h2"));

            textNode = (TextNode) tagNode.getTextNode();
            Assert.IsNotNull(textNode.getValue());
            Assert.AreEqual(textNode.getValue(), ("Hello World!\nHere comes the third Message!"));
            Assert.AreEqual(textNode.hasNodes(), (false));

            Assert.AreEqual(block.hasNodes(), (false));
            Assert.AreEqual(root.hasNodes(), (false));
        }
Ejemplo n.º 3
0
 protected void loadInParser(String fileName)
 {
     try
     {
         FileTemplateLoader loader = new FileTemplateLoader(
                 TestFileHelper.getParserResourcePath(""), "UTF-8");
         parser = new JadeParser(fileName, loader);
     }
     catch (IOException e)
     {
         Trace.WriteLine(e);
         Assert.Fail("template " + fileName + " was not found");
     }
     root = parser.parse();
 }
Ejemplo n.º 4
0
        public void test()
        {
            loadInParser("large_body_text_with_pipes.jade");
            pTag = (TagNode) root.pollNode();
            block = pTag.getBlock();
            Assert.IsNotNull(block.getNodes());
            Assert.IsNotNull(pTag);

            block = pTag.getBlock();
            Assert.IsNotNull(block.getNodes());

            Assert.IsNotNull(block.pollNode().getValue(), "Hello World!");
            Assert.IsNotNull(block.pollNode().getValue(), " Here comes the Message!");

            Assert.IsFalse(block.hasNodes());
        }
Ejemplo n.º 5
0
        public void shouldReturnABlockWithTokens2()
        {
            loadInParser("tags_with_attributes.jade");
            block = (BlockNode) root;
            Assert.IsNotNull(block.getNodes());

            // .myclass(title="my first div" alt="alt does not fit here")
            tag1 = block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getAttribute("class"), ("myclass"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("title"), ("my first div"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("alt"), ("alt does not fit here"));
            Assert.AreEqual(block.hasNodes(), (true));

            // #myid.c1.c2.c3(title="the third div with attribute")
            tag2 = block.pollNode();
            Assert.AreEqual(((TagNode) tag2).getAttribute("id"), ("myid"));
            Assert.AreEqual(((TagNode) tag2).getAttribute("class"), ("c1 c2 c3"));
            Assert.AreEqual(((TagNode) tag2).getAttribute("title"), ("the third div with attribute"));
            Assert.AreEqual(block.hasNodes(), (false));

            // .c1.c2.c3(title="the second div with attribute")
            block = ((TagNode) tag1).getBlock();
            tag3 = block.pollNode();
            Assert.AreEqual(((TagNode) tag3).getAttribute("class"), ("c1 c2 c3"));
            Assert.AreEqual(((TagNode) tag3).getAttribute("title"), ("the second div with attribute"));
            Assert.AreEqual(block.hasNodes(), (true));

            // #myid
            tag3 = block.pollNode();
            Assert.AreEqual(((TagNode) tag3).getAttribute("id"), ("myid"));
            Assert.AreEqual(block.hasNodes(), (false));

            // div#id1
            block = ((TagNode) tag2).getBlock();
            tag1 = block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getAttribute("id"), ("id1"));
            Assert.AreEqual(block.hasNodes(), (false));

            // span#id2.c1.c2.c3.c4(alt="alt")
            block = ((TagNode) tag1).getBlock();
            tag1 = block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getValue(), ("span"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("id"), ("id2"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("class"), ("c1 c2 c3 c4"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("alt"), ("alt"));
            Assert.AreEqual(block.hasNodes(), (false));
        }
Ejemplo n.º 6
0
        public void shouldReturnABlockWithTokens2()
        {
            loadInParser("css_class_and_id.jade");
            block = (BlockNode) root;
            Assert.IsNotNull(block.getNodes());

            // .myclass
            tag1 = block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getAttribute("class"), ("myclass"));
            Assert.AreEqual(block.hasNodes(), (true));

            // #myid.c1.c2.c3
            tag2 = block.pollNode();
            Assert.AreEqual(((TagNode) tag2).getAttribute("id"), ("myid"));
            Assert.AreEqual(((TagNode) tag2).getAttribute("class"), ("c1 c2 c3"));
            Assert.AreEqual(block.hasNodes(), (false));

            // .c1.c2.c3
            // #myid
            block = ((TagNode) tag1).getBlock();
            tag3 = block.pollNode();
            Assert.AreEqual(((TagNode) tag3).getAttribute("class"), ("c1 c2 c3"));
            Assert.AreEqual(block.hasNodes(), (true));
            tag3 = block.pollNode();
            Assert.AreEqual(((TagNode) tag3).getAttribute("id"), ("myid"));
            Assert.AreEqual(block.hasNodes(), (false));

            // div#id1
            block = ((TagNode) tag2).getBlock();
            tag1 = block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getAttribute("id"), ("id1"));
            Assert.AreEqual(block.hasNodes(), (false));

            // span#id2.c1.c2.c3.c4
            block = ((TagNode) tag1).getBlock();
            tag1 = block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getValue(), ("span"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("id"), ("id2"));
            Assert.AreEqual(((TagNode) tag1).getAttribute("class"), ("c1 c2 c3 c4"));
            Assert.AreEqual(block.hasNodes(), (false));
        }
Ejemplo n.º 7
0
 private List<BlockNode> getInjectionPoints(Node block)
 {
     List<BlockNode> result = new List<BlockNode>();
     foreach (Node node in block.getNodes())
     {
         if (node is BlockNode && !node.hasNodes()) {
         result.Add((BlockNode)node);
     } else if (node is ConditionalNode){
         foreach (IfConditionNode condition in ((ConditionalNode)node).getConditions())
         {
             result.AddRange(getInjectionPoints(condition.getBlock()));
         }
     } else if (node is CaseNode){
         foreach (CaseConditionNode condition in ((CaseNode)node).getCaseConditionNodes())
         {
             result.AddRange(getInjectionPoints(condition.getBlock()));
         }
     } else if (node.hasBlock())
     {
         result.AddRange(getInjectionPoints(node.getBlock()));
     }
     }
     return result;
 }
Ejemplo n.º 8
0
        public void shouldReturnTagsWithTexts()
        {
            loadInParser("tags_with_text.jade");
            block = (BlockNode) root;
            Assert.IsNotNull(block.getNodes());
            Assert.AreEqual(block.getNodes().Count, (2));

            tag1 = (TagNode) block.pollNode();
            Assert.AreEqual(((TagNode) tag1).getAttribute("class"), ("myclass"));
            Assert.IsNotNull(((TagNode) tag1).getTextNode());
            Assert.AreEqual(((TagNode) tag1).getTextNode().getValue(), ("Hello World!"));
            Assert.AreEqual(block.hasNodes(), (true));

            tag2 = block.pollNode();
            Assert.AreEqual(((TagNode) tag2).getAttribute("id"), ("myid2"));
            Assert.AreEqual(((TagNode) tag2).getTextNode().getValue(), ("without words"));
            Assert.AreEqual(block.hasNodes(), (false));

            block = ((TagNode) tag1).getBlock();
            tag = block.pollNode();
            Assert.AreEqual(((TagNode) tag).getAttribute("class"), ("c1"));
            Assert.AreEqual(((TagNode) tag).getTextNode().getValue(), ("The quick brown fox"));
            Assert.AreEqual(block.hasNodes(), (true));

            tag = block.pollNode();
            Assert.AreEqual(((TagNode) tag).getAttribute("class"), ("c2"));
            Assert.AreEqual(((TagNode) tag).getAttribute("id"), ("myid"));
            Assert.AreEqual(((TagNode) tag).getTextNode().getValue(), ("jumpes over the lazy dog"));
            Assert.AreEqual(block.hasNodes(), (false));

            block = ((TagNode) tag2).getBlock();
            tag = block.pollNode();
            Assert.AreEqual(((TagNode) tag).getAttribute("id"), ("id1"));
            Assert.AreEqual(((TagNode) tag).getTextNode().getValue(), ("without music"));
            Assert.AreEqual(block.hasNodes(), (false));
        }
Ejemplo n.º 9
0
 public void setTextNode(Node textNode)
 {
     this.textNode = textNode;
 }
Ejemplo n.º 10
0
 public void setBlock(Node block)
 {
     this.block = block;
 }
Ejemplo n.º 11
0
 public void setElseNode(Node elseNode)
 {
     this.elseNode = elseNode;
 }
Ejemplo n.º 12
0
 public void push(Node node)
 {
     if (node == null)
     {
         throw new ApplicationException();
     }
     nodes.AddLast(node);
 }
Ejemplo n.º 13
0
 public Compiler(Node rootNode)
 {
     this.rootNode = rootNode;
 }
Ejemplo n.º 14
0
        public void shouldReturnABlockWithTokens2()
        {
            loadInParser("complex_indent_outdent_file.jade");
            block = (BlockNode) root;
            Assert.IsNotNull(block.getNodes());

            head = block.pollNode();
            body = block.pollNode();
            Assert.AreEqual(head.getValue(), ("head"));
            Assert.AreEqual(body.getValue(), ("body"));
            Assert.AreEqual(block.hasNodes(), (false));

            block = ((TagNode) head).getBlock();
            Assert.AreEqual(block.pollNode().getValue(), ("meta"));
            Assert.AreEqual(block.pollNode().getValue(), ("meta"));
            Assert.AreEqual(block.hasNodes(), (false));

            block = ((TagNode) body).getBlock();
            Assert.AreEqual(block.pollNode().getValue(), ("div0"));

            div1 = block.pollNode();
            Assert.AreEqual(div1.getValue(), ("div1"));

            div2 = block.pollNode();
            Assert.AreEqual(div2.getValue(), ("div2"));

            div3 = block.pollNode();
            Assert.AreEqual(div3.getValue(), ("div3"));

            div4 = block.pollNode();
            Assert.AreEqual(div4.getValue(), ("div4"));

            div5 = block.pollNode();
            Assert.AreEqual(div5.getValue(), ("div5"));

            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div1).getBlock();
            Assert.AreEqual(block.pollNode().getValue(), ("span"));
            Assert.AreEqual(block.pollNode().getValue(), ("span"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div2).getBlock();
            ul1 = block.pollNode();
            Assert.AreEqual(ul1.getValue(), ("ul1"));
            ul2 = block.pollNode();
            Assert.AreEqual(ul2.getValue(), ("ul2"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div3).getBlock();
            Assert.AreEqual(block.pollNode().getValue(), ("span"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div4).getBlock();
            Assert.AreEqual(block.pollNode().getValue(), ("h1"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div5).getBlock();
            div6 = block.pollNode();
            Assert.AreEqual(div6.getValue(), ("div6"));
            div7 = block.pollNode();
            Assert.AreEqual(div7.getValue(), ("div7"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div6).getBlock();
            div8 = block.pollNode();
            Assert.AreEqual(div8.getValue(), ("div8"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div8).getBlock();
            span = block.pollNode();
            Assert.AreEqual(span.getValue(), ("span"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) span).getBlock();
            em = block.pollNode();
            Assert.AreEqual(em.getValue(), ("em"));
            Assert.AreEqual(block.hasNodes(), (false));

            // ===============================================

            block = ((TagNode) div7).getBlock();
            Assert.AreEqual(block.pollNode().getValue(), ("span"));
            Assert.AreEqual(block.hasNodes(), (false));
        }
Ejemplo n.º 15
0
 public JadeCompilerException(Node node, TemplateLoader templateLoader, String message)
     : base(message, node.getFileName(), node.getLineNumber(), templateLoader, null)
 {
     ;
 }
Ejemplo n.º 16
0
 //private static readonly long serialVersionUID = -126617495230190225L;
 public JadeCompilerException(Node node, TemplateLoader templateLoader, Exception e)
     : base(e.Message, node.getFileName(), node.getLineNumber(), templateLoader, e)
 {
     ;
 }
Ejemplo n.º 17
0
 //throws ExpressionException
 private bool checkCondition(JadeModel model, Node caseConditionNode)
 {
     return ExpressionHandler.evaluateBooleanExpression(value + " == " + caseConditionNode.getValue(), model).Value;
 }
Ejemplo n.º 18
0
 public void setCodeNode(Node codeNode)
 {
     this.codeNode = codeNode;
 }
Ejemplo n.º 19
0
 public void setTextBlock(Node textBlock)
 {
     this.textBlock = textBlock;
 }