use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method assertOnlyText.
private static void assertOnlyText(String code) {
StringReader reader = new StringReader(code);
List<Node> nodeList = new PageLexer().parse(reader);
assertThat(nodeList).isNotEmpty().allMatch(node -> node.getNodeType() == NodeType.TEXT);
}
use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method testLexer.
@Test
public void testLexer() throws FileNotFoundException {
String fileName = "src/test/resources/src/main/webapp/create-salesorder.xhtml";
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(new FileReader(fileName));
assertThat(nodeList.size()).isGreaterThan(50);
// check tagnodes
for (Node node : nodeList) {
if (node instanceof TagNode) {
assertThat(node.getCode()).startsWith("<");
assertThat(node.getCode()).endsWith(">");
}
}
showHierarchy(nodeList);
// check hierarchy
for (Node node : nodeList) {
if (node instanceof TagNode) {
TagNode tagNode = (TagNode) node;
if (!tagNode.isEndElement()) {
if (tagNode.equalsElementName("define")) {
assertThat(tagNode.getChildren()).as("Tag should have children: " + tagNode.getCode()).isNotEmpty();
} else if (tagNode.equalsElementName("outputText")) {
assertThat(tagNode.getChildren()).isEmpty();
}
}
}
}
}
use of org.sonar.plugins.html.node.Node 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);
assertThat(nodeList).hasSize(3);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
assertThat(nodeList.get(1)).isInstanceOf(TextNode.class);
assertThat(nodeList.get(2)).isInstanceOf(TagNode.class);
TagNode tagNode = (TagNode) nodeList.get(0);
assertThat(tagNode.getAttributes()).hasSize(1);
}
use of org.sonar.plugins.html.node.Node 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.html.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method testComment.
@Test
public void testComment() {
String fragment = "<!-- text --><p>aaa</p>";
StringReader reader = new StringReader(fragment);
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(reader);
assertThat(nodeList).hasSize(4);
assertThat(nodeList.get(0)).isInstanceOf(CommentNode.class);
}
Aggregations