use of org.sonar.plugins.html.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);
assertThat(nodeList).hasSize(1);
TagNode tagNode = (TagNode) nodeList.get(0);
assertThat(tagNode.getAttributes()).hasSize(1);
}
use of org.sonar.plugins.html.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.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method assertNodes.
private static void assertNodes(String code, TestNode expected) {
StringReader reader = new StringReader(code);
List<Node> nodes = new PageLexer().parse(reader);
assertNodes((TagNode) nodes.get(0), expected);
}
use of org.sonar.plugins.html.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);
assertThat(nodeList).hasSize(1);
TagNode tagNode = (TagNode) nodeList.get(0);
assertThat(tagNode.getAttributes()).hasSize(2);
// the embedded tags are added as attributes
assertThat(tagNode.getAttributes().get(0).getName()).isEqualTo("value");
assertThat(tagNode.getAttributes().get(0).getValue()).isEqualTo("<%= key -%>");
assertThat(tagNode.getAttributes().get(1).getName()).isEqualTo("<%= 'selected' if alert.operator==key -%>");
assertThat(tagNode.getAttributes().get(1).getValue()).isEmpty();
}
use of org.sonar.plugins.html.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));
assertThat(nodeList).hasSize(12);
// check script node
Node node = nodeList.get(2);
assertThat(node).isInstanceOf(TagNode.class);
TagNode scriptNode = (TagNode) node;
assertThat(scriptNode.getNodeName()).isEqualTo("script");
assertThat(scriptNode.getChildren()).isEmpty();
}
Aggregations