Search in sources :

Example 1 with TagNode

use of org.sonar.plugins.web.node.TagNode in project sonar-web by SonarSource.

the class PageLexerTest method nestedQuotes.

@Test
public void nestedQuotes() {
    String fragment = "<tr class=\"<c:if test='${count%2==0}'>even</c:if>" + "<c:if test='${count%2!=0}'>odd</c:if><c:if test='${ActionType==\"baseline\"}'> baseline</c:if>\">";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(1, nodeList.size());
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertEquals(1, tagNode.getAttributes().size());
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 2 with TagNode

use of org.sonar.plugins.web.node.TagNode in project sonar-web by SonarSource.

the class PageLexerTest method should_recover_on_invalid_attribute.

@Test
public void should_recover_on_invalid_attribute() {
    PageLexer lexer = new PageLexer();
    List<Node> nodes = lexer.parse(new StringReader("<foo = bar=42>"));
    assertThat(nodes).hasSize(1);
    assertThat(((TagNode) nodes.get(0)).getAttribute("bar")).isEqualTo("42");
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 3 with TagNode

use of org.sonar.plugins.web.node.TagNode in project sonar-web by SonarSource.

the class PageLexerTest method printTag.

private void printTag(StringBuilder sb, TagNode node, int indent) {
    sb.append('\n');
    for (int i = 0; i < indent; i++) {
        sb.append(" ");
    }
    sb.append('<');
    sb.append(node.getNodeName());
    if (node.getChildren().size() > 0) {
        sb.append('>');
        for (TagNode child : node.getChildren()) {
            printTag(sb, child, indent + 1);
        }
        sb.append('\n');
        for (int i = 0; i < indent; i++) {
            sb.append(" ");
        }
        sb.append("</");
        sb.append(node.getNodeName());
        sb.append('>');
    } else {
        sb.append("/>");
    }
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode)

Example 4 with TagNode

use of org.sonar.plugins.web.node.TagNode in project sonar-web by SonarSource.

the class PageLexerTest method showHierarchy.

private void showHierarchy(List<Node> nodeList) {
    StringBuilder sb = new StringBuilder();
    for (Node node : nodeList) {
        if (node.getClass() == TagNode.class && ((TagNode) node).getParent() == null) {
            TagNode root = (TagNode) node;
            printTag(sb, root, 0);
        // System.out.print(sb.toString());
        }
    }
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) TagNode(org.sonar.plugins.web.node.TagNode)

Example 5 with TagNode

use of org.sonar.plugins.web.node.TagNode in project sonar-web by SonarSource.

the class PageLexerTest method javaScriptWithNestedTags.

@Test
public void javaScriptWithNestedTags() throws FileNotFoundException {
    String fileName = "src/test/resources/lexer/javascript-nestedtags.jsp";
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(new FileReader(fileName));
    assertEquals(12, nodeList.size());
    // check script node
    Node node = nodeList.get(2);
    assertTrue(node instanceof TagNode);
    TagNode scriptNode = (TagNode) node;
    assertEquals("script", scriptNode.getNodeName());
    assertEquals(0, scriptNode.getChildren().size());
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) FileReader(java.io.FileReader) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Aggregations

TagNode (org.sonar.plugins.web.node.TagNode)16 Node (org.sonar.plugins.web.node.Node)13 CommentNode (org.sonar.plugins.web.node.CommentNode)11 DirectiveNode (org.sonar.plugins.web.node.DirectiveNode)11 TextNode (org.sonar.plugins.web.node.TextNode)11 Test (org.junit.Test)10 StringReader (java.io.StringReader)8 FileReader (java.io.FileReader)2 Attribute (org.sonar.plugins.web.node.Attribute)2 ArrayList (java.util.ArrayList)1 CodeReader (org.sonar.channel.CodeReader)1