use of org.sonar.plugins.html.visitor.HtmlSourceCode 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");
}
HtmlSourceCode result = new HtmlSourceCode(new TestInputFileBuilder("key", /* wrong path */
".").setLanguage(HtmlConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()).build());
walker.scan(new PageLexer().parse(reader), // won't be able to resolve the file
result);
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class JspScriptletCheckTest method test.
@Test
public void test() throws Exception {
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/jspScriptletCheck.html"), new JspScriptletCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Replace this scriptlet using tag libraries and expression language.").next().atLine(8);
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class NestedJavaScriptCheckTest method dangling_script_end_tag_should_result_in_a_violation.
@Test
public void dangling_script_end_tag_should_result_in_a_violation() {
NestedJavaScriptCheck check = new NestedJavaScriptCheck();
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/NestedJavaScriptCheck/DanglingScriptEndTag.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(4).noMore();
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class NestedJavaScriptCheckTest method no_violations_should_be_reported_for_correct_script_tags.
@Test
public void no_violations_should_be_reported_for_correct_script_tags() {
NestedJavaScriptCheck check = new NestedJavaScriptCheck();
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/NestedJavaScriptCheck/CorrectScriptTags.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).noMore();
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class ResourceIntegrityCheckTest method test.
@Test
public void test() {
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/resourceIntegrityCheck.html"), new ResourceIntegrityCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLocation(1, 0, 1, 47).withMessage("Make sure not using resource integrity feature is safe here.").next().atLocation(2, 0, 2, 41).withMessage("Make sure not using resource integrity feature is safe here.").next().atLocation(3, 0, 3, 46).withMessage("Make sure not using resource integrity feature is safe here.").next().atLocation(4, 0, 4, 61).withMessage("Make sure not using resource integrity feature is safe here.");
}
Aggregations