Search in sources :

Example 56 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class NonConsecutiveHeadingCheckTest method h2_with_h1.

@Test
public void h2_with_h1() throws Exception {
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/NonConsecutiveHeadingCheck/H2WithH1.html"), new NonConsecutiveHeadingCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues());
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Example 57 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class NonConsecutiveHeadingCheckTest method h5_with_h4.

@Test
public void h5_with_h4() throws Exception {
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/NonConsecutiveHeadingCheck/H5WithH4.html"), new NonConsecutiveHeadingCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Do not skip level H3.");
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Example 58 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class TableHeaderReferenceCheckTest method detected.

@Test
public void detected() throws Exception {
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/TableHeaderReferenceCheck.html"), new TableHeaderReferenceCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLocation(35, 4, 35, 22).withMessage("id \"bar\" in \"headers\" does not reference any <th> header.").next().atLine(56).withMessage("id \"bar\" in \"headers\" does not reference any <th> header.").next().atLine(78).withMessage("id \"oof\" in \"headers\" does not reference any <th> header.").next().atLine(89).withMessage("id \"bar\" in \"headers\" reference the header of another column/row.").next().atLine(90).withMessage("id \"foo\" in \"headers\" reference the header of another column/row.").next().atLine(108).withMessage("id \"oof\" in \"headers\" does not reference any <th> header.").next().atLine(119).withMessage("id \"bar\" in \"headers\" reference the header of another column/row.").next().atLine(123).withMessage("id \"foo\" in \"headers\" reference the header of another column/row.").next().atLine(152).withMessage("id \"bar\" in \"headers\" does not reference any <th> header.").next().atLine(220).withMessage("id \"bar\" in \"headers\" does not reference any <th> header.").next().atLine(227).withMessage("id \"bar\" in \"headers\" does not reference any <th> header.").next().atLine(275).withMessage("id \"foo\" in \"headers\" does not reference any <th> header.").next().atLine(281).withMessage("id \"foo\" in \"headers\" does not reference any <th> header.");
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Example 59 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class PageCountLines method addMeasures.

private void addMeasures() {
    HtmlSourceCode htmlSourceCode = getHtmlSourceCode();
    htmlSourceCode.addMeasure(CoreMetrics.NCLOC, detailedLinesOfCode.size());
    htmlSourceCode.addMeasure(CoreMetrics.COMMENT_LINES, detailedLinesOfComments.size());
    htmlSourceCode.setDetailedLinesOfCode(detailedLinesOfCode);
    LOG.debug("HtmlSensor: " + getHtmlSourceCode().toString() + ": " + detailedLinesOfComments.size() + "," + headerCommentLines + "," + blankLines);
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode)

Example 60 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class PageCountLinesTest method testCountLines.

@Test
public void testCountLines() {
    List<Node> nodeList = lexer.parse(readFile("src/main/webapp/user-properties.jsp"));
    assertThat(nodeList.size()).isGreaterThan(100);
    HtmlSourceCode htmlSourceCode = createHtmlSourceCode("test/user-properties.jsp");
    scanner.scan(nodeList, htmlSourceCode);
    assertThat(htmlSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(224);
    assertThat(htmlSourceCode.getDetailedLinesOfCode().size()).isEqualTo(224);
    assertThat(htmlSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(14);
}
Also used : Node(org.sonar.plugins.html.node.Node) HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) Test(org.junit.Test)

Aggregations

HtmlSourceCode (org.sonar.plugins.html.visitor.HtmlSourceCode)115 File (java.io.File)111 Test (org.junit.Test)111 InputFile (org.sonar.api.batch.fs.InputFile)8 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)3 PageLexer (org.sonar.plugins.html.lex.PageLexer)3 Node (org.sonar.plugins.html.node.Node)3 HtmlAstScanner (org.sonar.plugins.html.visitor.HtmlAstScanner)3 FileReader (java.io.FileReader)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ExpectedException (org.junit.rules.ExpectedException)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 ComplexityVisitor (org.sonar.plugins.html.analyzers.ComplexityVisitor)1 PageCountLines (org.sonar.plugins.html.analyzers.PageCountLines)1 VueLexer (org.sonar.plugins.html.lex.VueLexer)1