use of org.sonar.plugins.web.node.Node 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.Node 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.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);
assertEquals(4, nodeList.size());
assertTrue(nodeList.get(0) instanceof CommentNode);
}
use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method testRuby.
@Test
public void testRuby() throws FileNotFoundException {
String fileName = "src/test/resources/src/main/webapp/select_user.html.erb";
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(new FileReader(fileName));
assertTrue(nodeList.size() > 50);
// TODO - better parsing of erb.
}
use of org.sonar.plugins.web.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());
}
}
}
Aggregations