use of org.sonar.plugins.web.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);
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 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");
}
use of org.sonar.plugins.web.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("/>");
}
}
use of org.sonar.plugins.web.node.TagNode 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());
}
}
}
use of org.sonar.plugins.web.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));
assertEquals(12, nodeList.size());
// check script node
Node node = nodeList.get(2);
assertTrue(node instanceof TagNode);
TagNode scriptNode = (TagNode) node;
assertEquals("script", scriptNode.getNodeName());
assertEquals(0, scriptNode.getChildren().size());
}
Aggregations