Search in sources :

Example 21 with TagNode

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

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

the class PageLexerTest method testNestedTagInAttribute.

@Test
public void testNestedTagInAttribute() {
    String fragment = "<td id=\"typeCellHeader\"<c:if test='${param.typeNormalOrError == \"error\"}'>" + "style=\"display:none;\"</c:if>>Type" + "</td>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).hasSize(3);
    assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
    assertThat(nodeList.get(1)).isInstanceOfAny(TextNode.class);
    assertThat(nodeList.get(2)).isInstanceOf(TagNode.class);
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertThat(tagNode.getAttributes()).hasSize(4);
    // the embedded tags are added as attributes
    assertThat(tagNode.getAttributes().get(1).getValue()).isEmpty();
    assertThat(tagNode.getAttributes().get(3).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)

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