Search in sources :

Example 1 with Node

use of org.sonar.plugins.web.node.Node 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 Node

use of org.sonar.plugins.web.node.Node 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 Node

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

the class PageLexerTest method testComment.

@Test
public void testComment() {
    String fragment = "<!-- text --><p>aaa</p>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(4, nodeList.size());
    assertTrue(nodeList.get(0) instanceof CommentNode);
}
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) CommentNode(org.sonar.plugins.web.node.CommentNode) Test(org.junit.Test)

Example 4 with Node

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

the class PageLexerTest method testRuby.

@Test
public void testRuby() throws FileNotFoundException {
    String fileName = "src/test/resources/src/main/webapp/select_user.html.erb";
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(new FileReader(fileName));
    assertTrue(nodeList.size() > 50);
// TODO - better parsing of erb.
}
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) Test(org.junit.Test)

Example 5 with Node

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

Aggregations

Node (org.sonar.plugins.web.node.Node)25 TagNode (org.sonar.plugins.web.node.TagNode)19 Test (org.junit.Test)18 TextNode (org.sonar.plugins.web.node.TextNode)17 CommentNode (org.sonar.plugins.web.node.CommentNode)15 DirectiveNode (org.sonar.plugins.web.node.DirectiveNode)15 StringReader (java.io.StringReader)10 FileReader (java.io.FileReader)7 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 File (java.io.File)3 WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)3 ArrayList (java.util.ArrayList)2 CodeReader (org.sonar.channel.CodeReader)2 Attribute (org.sonar.plugins.web.node.Attribute)2 List (java.util.List)1 InputFile (org.sonar.api.batch.fs.InputFile)1 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)1 Channel (org.sonar.channel.Channel)1 PageLexer (org.sonar.plugins.web.lex.PageLexer)1