use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class PageCountLinesTest method testCountLinesJspFile.
@Test
public void testCountLinesJspFile() throws FileNotFoundException {
List<Node> nodeList = lexer.parse(new FileReader(TestUtils.getResource("checks/AvoidHtmlCommentCheck/document.jsp")));
String relativePath = "testdocument.jsp";
WebSourceCode webSourceCode = new WebSourceCode(new DefaultInputFile("key", relativePath).setModuleBaseDir(new File(".").toPath()));
scanner.scan(nodeList, webSourceCode, Charsets.UTF_8);
assertThat(webSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(2);
assertThat(webSourceCode.getDetailedLinesOfCode()).containsOnly(1, 3);
assertThat(webSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(6);
assertThat(webSourceCode.getDetailedLinesOfComments()).containsOnly(2, 4, 6, 7, 8, 10);
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class RequiredAttributeCheckTest method checkRepetition.
@Test
public void checkRepetition() {
RequiredAttributeCheck check = new RequiredAttributeCheck();
check.attributes = "img.alt,script.type";
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/RequiredAttributeCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(2).withMessage("Add the missing \"alt\" to element \"img\".").next().atLine(7).withMessage("Add the missing \"type\" to element \"script\".");
sourceCode = TestHelper.scan(new File("src/test/resources/checks/RequiredAttributeCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(2).withMessage("Add the missing \"alt\" to element \"img\".").next().atLine(7).withMessage("Add the missing \"type\" to element \"script\".");
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class ComplexityCheckTest method custom.
@Test
public void custom() {
ComplexityCheck check = new ComplexityCheck();
check.max = 15;
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/ComplexityCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(null).withCost(2d).withMessage("Split this file to reduce complexity per file from 17 to no more than the 15 authorized.");
}
Aggregations