Search in sources :

Example 6 with Node

use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method testDirectiveNode.

@Test
public void testDirectiveNode() {
    String directive = "<!docTyPE html " + "PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
    DoctypeTokenizer tokenizer = new DoctypeTokenizer("<!DOCTYPE", ">");
    List<Node> nodeList = new ArrayList<>();
    CodeReader codeReader = new CodeReader(directive);
    tokenizer.consume(codeReader, nodeList);
    assertThat(nodeList).hasSize(1);
    Node node = nodeList.get(0);
    assertThat(node).isInstanceOf(DirectiveNode.class);
    assertThat(((DirectiveNode) node).getAttributes()).hasSize(4);
}
Also used : CommentNode(org.sonar.plugins.html.node.CommentNode) Node(org.sonar.plugins.html.node.Node) TextNode(org.sonar.plugins.html.node.TextNode) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) TagNode(org.sonar.plugins.html.node.TagNode) ArrayList(java.util.ArrayList) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) CodeReader(org.sonar.channel.CodeReader) Test(org.junit.Test)

Example 7 with Node

use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method attribute_value_starting_with_quote.

@Test
public void attribute_value_starting_with_quote() {
    StringReader reader = new StringReader("<img src=\"'a'\"/>");
    List<Node> nodeList = new PageLexer().parse(reader);
    assertThat(nodeList).hasSize(1);
    assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
    TagNode node = (TagNode) nodeList.get(0);
    Attribute attribute = node.getAttributes().get(0);
    assertThat(attribute.getName()).isEqualTo("src");
    assertThat(attribute.getValue()).isEqualTo("'a'");
}
Also used : Attribute(org.sonar.plugins.html.node.Attribute) CommentNode(org.sonar.plugins.html.node.CommentNode) Node(org.sonar.plugins.html.node.Node) TextNode(org.sonar.plugins.html.node.TextNode) DirectiveNode(org.sonar.plugins.html.node.DirectiveNode) TagNode(org.sonar.plugins.html.node.TagNode) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.html.node.TagNode) Test(org.junit.Test)

Example 8 with Node

use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.

the class VueLexerTest method testMalformedTemplate2.

@Test
public void testMalformedTemplate2() {
    String fragment = "<foo/><bar/></template>";
    StringReader reader = new StringReader(fragment);
    VueLexer lexer = new VueLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).isEmpty();
}
Also used : Node(org.sonar.plugins.html.node.Node) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 9 with Node

use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.

the class VueLexerTest method testVoidTemplate.

@Test
public void testVoidTemplate() {
    String fragment = "<template></template>";
    StringReader reader = new StringReader(fragment);
    VueLexer lexer = new VueLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).isEmpty();
}
Also used : Node(org.sonar.plugins.html.node.Node) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 10 with Node

use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.

the class VueLexerTest method testNestedTemplates.

@Test
public void testNestedTemplates() {
    String fragment = "<template><template><template><template></template></template></template></template>";
    StringReader reader = new StringReader(fragment);
    VueLexer lexer = new VueLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).hasSize(6);
}
Also used : Node(org.sonar.plugins.html.node.Node) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Node (org.sonar.plugins.html.node.Node)39 Test (org.junit.Test)28 TagNode (org.sonar.plugins.html.node.TagNode)24 StringReader (java.io.StringReader)23 TextNode (org.sonar.plugins.html.node.TextNode)21 CommentNode (org.sonar.plugins.html.node.CommentNode)19 DirectiveNode (org.sonar.plugins.html.node.DirectiveNode)19 FileReader (java.io.FileReader)4 Attribute (org.sonar.plugins.html.node.Attribute)3 HtmlSourceCode (org.sonar.plugins.html.visitor.HtmlSourceCode)3 ArrayList (java.util.ArrayList)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 CodeReader (org.sonar.channel.CodeReader)2 File (java.io.File)1 Reader (java.io.Reader)1 ArrayDeque (java.util.ArrayDeque)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 InputFile (org.sonar.api.batch.fs.InputFile)1 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)1