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());
}
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());
}
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);
}
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();
}
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());
}
Aggregations