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)); }
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_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()); }
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)); }
private Node parseTag() { // ast-filter look-ahead int i = 2; if (lookahead(i) is Attribute) { i++; } if (lookahead(i) is Colon) { i++; if (lookahead(i) is Indent) { return this.parseASTFilter(); } } Token token = nextToken(); String name = token.getValue(); TagNode tagNode = new TagNode(); tagNode.setLineNumber(_jadeLexer.getLineno()); tagNode.setFileName(filename); tagNode.setName(name); tagNode.setValue(name); tagNode.setSelfClosing(token.isSelfClosing()); while (true) { Token incomingToken = peek(); if (incomingToken is CssId) { Token tok = nextToken(); tagNode.addAttribute("id", tok.getValue()); continue; } else if (incomingToken is CssClass) { Token tok = nextToken(); tagNode.addAttribute("class", tok.getValue()); continue; } else if (incomingToken is Attribute) { Attribute tok = (Attribute) nextToken(); tagNode.addAttributes(tok.getAttributes()); tagNode.setSelfClosing(tok.isSelfClosing()); continue; } else { break; } } // check immediate '.' bool dot = false; if (peek() is Dot) { dot = true; tagNode.setTextOnly(true); nextToken(); } // (text | code | ':')? if (peek() is Text) { tagNode.setTextNode(parseText()); } else if (peek() is Jade.Lexer.Tokens.Expression) { tagNode.setCodeNode(parseCode()); } else if (peek() is Colon) { Token next = nextToken(); BlockNode block = new BlockNode(); block.setLineNumber(next.getLineNumber()); block.setFileName(filename); tagNode.setBlock(block); block.push(parseExpr()); } // newline* while (peek() is Newline) { nextToken(); } if (!tagNode.isTextOnly()) { if (Array.IndexOf(textOnlyTags, tagNode.getName()) >= 0) { tagNode.setTextOnly(true); } } // script special-case if ("script".Equals(tagNode.getName())) { String type = tagNode.getAttribute("type"); if (!dot && StringUtils.isNotBlank(type)) { String cleanType = type.replaceAll("^['\"]|['\"]$", ""); if (!"text/javascript".Equals(cleanType)) { tagNode.setTextOnly(false); } } } if (peek() is Indent) { if (tagNode.isTextOnly()) { _jadeLexer.setPipeless(true); tagNode.setTextNode(parseTextBlock()); _jadeLexer.setPipeless(false); } else { Node blockNode = block(); if (tagNode.hasBlock()) { tagNode.getBlock().getNodes().AppendRange(blockNode.getNodes()); } else { tagNode.setBlock(blockNode); } } } return tagNode; }
public TagNodeTest() { tagNode = new TagNode(); template = new JadeTemplate(); template.setMode(Jade4Net.Mode.XHTML); }