Search in sources :

Example 16 with TagNode

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

the class PageLexerTest method escapeCharacters.

@Test
public void escapeCharacters() {
    String fragment = "<c:when test=\"${citaflagurge eq \\\"S\\\"}\">";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).hasSize(1);
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertThat(tagNode.getAttributes()).hasSize(1);
}
Also used : CommentNode(org.sonar.plugins.html.node.CommentNode) Node(org.sonar.plugins.html.node.Node) TextNode(org.sonar.plugins.html.node.TextNode) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) TagNode(org.sonar.plugins.html.node.TagNode) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.html.node.TagNode) Test(org.junit.Test)

Example 17 with TagNode

use of org.sonar.plugins.html.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.html.node.TagNode)

Example 18 with TagNode

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

the class PageLexerTest method assertNodes.

private static void assertNodes(String code, TestNode expected) {
    StringReader reader = new StringReader(code);
    List<Node> nodes = new PageLexer().parse(reader);
    assertNodes((TagNode) nodes.get(0), expected);
}
Also used : CommentNode(org.sonar.plugins.html.node.CommentNode) Node(org.sonar.plugins.html.node.Node) TextNode(org.sonar.plugins.html.node.TextNode) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) TagNode(org.sonar.plugins.html.node.TagNode) StringReader(java.io.StringReader)

Example 19 with TagNode

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

the class PageLexerTest method testNestedScriptlet.

@Test
public void testNestedScriptlet() {
    String fragment = "<option value=\"<%= key -%>\" <%= 'selected' if alert.operator==key -%>>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).hasSize(1);
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertThat(tagNode.getAttributes()).hasSize(2);
    // the embedded tags are added as attributes
    assertThat(tagNode.getAttributes().get(0).getName()).isEqualTo("value");
    assertThat(tagNode.getAttributes().get(0).getValue()).isEqualTo("<%= key -%>");
    assertThat(tagNode.getAttributes().get(1).getName()).isEqualTo("<%= 'selected' if alert.operator==key -%>");
    assertThat(tagNode.getAttributes().get(1).getValue()).isEmpty();
}
Also used : CommentNode(org.sonar.plugins.html.node.CommentNode) Node(org.sonar.plugins.html.node.Node) TextNode(org.sonar.plugins.html.node.TextNode) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) TagNode(org.sonar.plugins.html.node.TagNode) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.html.node.TagNode) Test(org.junit.Test)

Example 20 with TagNode

use of org.sonar.plugins.html.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));
    assertThat(nodeList).hasSize(12);
    // check script node
    Node node = nodeList.get(2);
    assertThat(node).isInstanceOf(TagNode.class);
    TagNode scriptNode = (TagNode) node;
    assertThat(scriptNode.getNodeName()).isEqualTo("script");
    assertThat(scriptNode.getChildren()).isEmpty();
}
Also used : CommentNode(org.sonar.plugins.html.node.CommentNode) Node(org.sonar.plugins.html.node.Node) TextNode(org.sonar.plugins.html.node.TextNode) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) TagNode(org.sonar.plugins.html.node.TagNode) FileReader(java.io.FileReader) TagNode(org.sonar.plugins.html.node.TagNode) Test(org.junit.Test)

Aggregations

TagNode (org.sonar.plugins.html.node.TagNode)22 Node (org.sonar.plugins.html.node.Node)15 CommentNode (org.sonar.plugins.html.node.CommentNode)12 DirectiveNode (org.sonar.plugins.html.node.DirectiveNode)12 TextNode (org.sonar.plugins.html.node.TextNode)12 Test (org.junit.Test)10 StringReader (java.io.StringReader)9 Attribute (org.sonar.plugins.html.node.Attribute)3 FileReader (java.io.FileReader)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CodeReader (org.sonar.channel.CodeReader)1