Search in sources :

Example 31 with Node

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

the class PageLexerTest method testNestedComment.

@Test
public void testNestedComment() {
    String fragment = "<!-- text <!--><p>This is not part of the comment</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);
    assertThat(nodeList.get(1)).isInstanceOf(TagNode.class);
    assertThat(nodeList.get(2)).isInstanceOf(TextNode.class);
    assertThat(nodeList.get(3)).isInstanceOf(TagNode.class);
}
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) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 32 with Node

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

the class PageLexerTest method testNestedTagInAttribute.

@Test
public void testNestedTagInAttribute() {
    String fragment = "<td id=\"typeCellHeader\"<c:if test='${param.typeNormalOrError == \"error\"}'>" + "style=\"display:none;\"</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)).isInstanceOfAny(TextNode.class);
    assertThat(nodeList.get(2)).isInstanceOf(TagNode.class);
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertThat(tagNode.getAttributes()).hasSize(4);
    // the embedded tags are added as attributes
    assertThat(tagNode.getAttributes().get(1).getValue()).isEmpty();
    assertThat(tagNode.getAttributes().get(3).getValue()).isEmpty();
}
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) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.html.node.TagNode) Test(org.junit.Test)

Example 33 with Node

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

the class VueLexerTest method testMissingTemplate.

@Test
public void testMissingTemplate() {
    String fragment = "";
    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 34 with Node

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

the class VueLexerTest method testMalformedTemplate1.

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

Example 35 with Node

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

the class VueLexerTest method testEmptyTemplate.

@Test
public void testEmptyTemplate() {
    String fragment = "<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)

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