Search in sources :

Example 36 with Node

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

the class VueLexerTest method testMultipleTemplates.

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

Example 37 with Node

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

the class VueLexerTest method commentedTemplate.

@Test
public void commentedTemplate() {
    String fragment = "<!-- <template><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 38 with Node

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

the class VueLexerTest method testFilledTemplate.

@Test
public void testFilledTemplate() {
    String fragment = "<template>" + "<!-- some HTML code here -->" + "<p>Hello, World!</p>" + "<div>" + "Hello, again!" + "<ul>" + "<li>foo</li>" + "<li>bar</li>" + "</ul>" + "</div>" + "</template>";
    StringReader reader = new StringReader(fragment);
    VueLexer lexer = new VueLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertThat(nodeList).hasSize(15);
}
Also used : Node(org.sonar.plugins.html.node.Node) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 39 with Node

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

the class NoSonarScannerTest method scanNoSonar.

@Test
public void scanNoSonar() throws Exception {
    List<Node> nodeList;
    try (Reader reader = new StringReader(CONTENT)) {
        nodeList = new PageLexer().parse(reader);
    }
    InputFile inputFile = new TestInputFileBuilder("key", "dummy.jsp").setContents(CONTENT).setCharset(StandardCharsets.UTF_8).build();
    NoSonarFilter noSonarFilter = spy(new NoSonarFilter());
    HtmlAstScanner pageScanner = new HtmlAstScanner(Collections.emptyList());
    pageScanner.addVisitor(new NoSonarScanner(noSonarFilter));
    pageScanner.scan(nodeList, new HtmlSourceCode(inputFile));
    verify(noSonarFilter, times(1)).noSonarInFile(eq(inputFile), argThat(new IsOnlyIgnoringLine2()));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) PageLexer(org.sonar.plugins.html.lex.PageLexer) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) Node(org.sonar.plugins.html.node.Node) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) InputFile(org.sonar.api.batch.fs.InputFile) 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