Search in sources :

Example 11 with TagNode

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

the class PageLexerTest method testNestedTagInValue.

@Test
public void testNestedTagInValue() {
    String fragment = "<td label=\"Hello <c:if test='${param == true}'>World</c:if>\">Type</td>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(3, nodeList.size());
    assertTrue(nodeList.get(0) instanceof TagNode);
    assertTrue(nodeList.get(1) instanceof TextNode);
    assertTrue(nodeList.get(2) instanceof TagNode);
    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) TextNode(org.sonar.plugins.web.node.TextNode) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 12 with TagNode

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

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

the class PageLexerTest method testNestedComment.

@Test
public void testNestedComment() {
    String fragment = "<!-- text <!--><p>This is not part of the comment</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);
    assertTrue(nodeList.get(1) instanceof TagNode);
    assertTrue(nodeList.get(2) instanceof TextNode);
    assertTrue(nodeList.get(3) instanceof TagNode);
}
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) TextNode(org.sonar.plugins.web.node.TextNode) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 14 with TagNode

use of org.sonar.plugins.web.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);
    assertEquals(1, nodeList.size());
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertEquals(2, tagNode.getAttributes().size());
    // the embedded tags are added as attributes
    assertEquals(tagNode.getAttributes().get(0).getName(), "value");
    assertEquals(tagNode.getAttributes().get(0).getValue(), "<%= key -%>");
    assertEquals(tagNode.getAttributes().get(1).getName(), "<%= 'selected' if alert.operator==key -%>");
    assertThat(tagNode.getAttributes().get(1).getValue()).isEmpty();
}
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 15 with TagNode

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

the class PageLexerTest method testAttributeWithoutQuotes.

@Test
public void testAttributeWithoutQuotes() {
    final StringReader reader = new StringReader("<img src=http://foo/sfds?sjg a=1\tb=2\r\nc=3 />");
    final PageLexer lexer = new PageLexer();
    final List<Node> nodeList = lexer.parse(reader);
    assertEquals(1, nodeList.size());
    assertTrue(nodeList.get(0) instanceof TagNode);
    final TagNode node = (TagNode) nodeList.get(0);
    assertEquals(4, node.getAttributes().size());
    final Attribute attribute = node.getAttributes().get(0);
    assertEquals("src", attribute.getName());
    assertEquals("http://foo/sfds?sjg", attribute.getValue());
    final Attribute attributeA = node.getAttributes().get(1);
    assertEquals("a", attributeA.getName());
    assertEquals("1", attributeA.getValue());
    final Attribute attributeB = node.getAttributes().get(2);
    assertEquals("b", attributeB.getName());
    assertEquals("2", attributeB.getValue());
    final Attribute attributeC = node.getAttributes().get(3);
    assertEquals("c", attributeC.getName());
    assertEquals("3", attributeC.getValue());
}
Also used : Attribute(org.sonar.plugins.web.node.Attribute) 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)

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