use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class HeaderCheckTest method missing_header.
@Test
public void missing_header() {
HeaderCheck check = new HeaderCheck();
check.headerFormat = "<!-- Copyright foo -->";
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/HeaderCheck/MissingHeader.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(null).withMessage("Add or update the header of this file.");
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class HeaderCheckTest method scanWithWrongInputFile.
public static void scanWithWrongInputFile(File file, DefaultNodeVisitor visitor) {
HtmlAstScanner walker = new HtmlAstScanner(Collections.emptyList());
walker.addVisitor(visitor);
FileReader reader;
try {
reader = new FileReader(file);
} catch (Exception e) {
throw new IllegalArgumentException("unable to read file");
}
WebSourceCode result = new WebSourceCode(new DefaultInputFile("key", /* wrong path */
".").setLanguage(WebConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()));
walker.scan(new PageLexer().parse(reader), // won't be able to resolve the file
result, StandardCharsets.UTF_8);
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class HeaderCheckTest method regex1.
@Test
public void regex1() {
HeaderCheck check = new HeaderCheck();
check.headerFormat = "<!-- copyright \\d{4}\\n mycompany -->";
check.isRegularExpression = true;
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/HeaderCheck/Regex1.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).noMore();
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class HeaderCheckTest method regex2.
@Test
public void regex2() {
HeaderCheck check = new HeaderCheck();
check.headerFormat = "<!-- copyright \\d{4}\\n mycompany -->";
check.isRegularExpression = true;
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/HeaderCheck/Regex2.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(null).withMessage("Add or update the header of this file.");
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class MultiplePageDirectivesCheckTest method test2.
@Test
public void test2() throws Exception {
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/multiplePageDirectivesCheck2.html"), new MultiplePageDirectivesCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(3).withMessage("Combine these 2 page directives into one.");
}
Aggregations