use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method javaScriptWithComments.
@Test
public void javaScriptWithComments() throws FileNotFoundException {
String fileName = "src/test/resources/lexer/script-with-comments.jsp";
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(new FileReader(fileName));
assertThat(nodeList).hasSize(3);
}
use of org.sonar.plugins.html.node.Node 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);
assertThat(nodeList).hasSize(1);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
final TagNode node = (TagNode) nodeList.get(0);
assertThat(node.getAttributes()).hasSize(4);
final Attribute attribute = node.getAttributes().get(0);
assertThat(attribute.getName()).isEqualTo("src");
assertThat(attribute.getValue()).isEqualTo("http://foo/sfds?sjg");
final Attribute attributeA = node.getAttributes().get(1);
assertThat(attributeA.getName()).isEqualTo("a");
assertThat(attributeA.getValue()).isEqualTo("1");
final Attribute attributeB = node.getAttributes().get(2);
assertThat(attributeB.getName()).isEqualTo("b");
assertThat(attributeB.getValue()).isEqualTo("2");
final Attribute attributeC = node.getAttributes().get(3);
assertThat(attributeC.getName()).isEqualTo("c");
assertThat(attributeC.getValue()).isEqualTo("3");
}
use of org.sonar.plugins.html.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));
assertThat(nodeList.size()).isGreaterThan(50);
// TODO - better parsing of erb.
}
use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method assertSingleTag.
private void assertSingleTag(String code) {
StringReader reader = new StringReader(code);
List<Node> nodeList = new PageLexer().parse(reader);
assertThat(nodeList).hasSize(1);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
}
use of org.sonar.plugins.html.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");
}
Aggregations