@Test public void testHighlighting() { assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 3)).isEmpty(); tester.newHighlighting() .onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()) .highlight(1, 0, 1, 5, TypeOfText.ANNOTATION) .highlight(8, 10, TypeOfText.CONSTANT) .highlight(9, 10, TypeOfText.COMMENT) .save(); assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 3)).containsExactly(TypeOfText.ANNOTATION); assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 9)).containsExactly(TypeOfText.CONSTANT, TypeOfText.COMMENT); }
@Test(expected = UnsupportedOperationException.class) public void duplicateHighlighting() { tester.newHighlighting() .onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()) .highlight(1, 0, 1, 5, TypeOfText.ANNOTATION) .save(); tester.newHighlighting() .onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()) .highlight(1, 0, 1, 5, TypeOfText.ANNOTATION) .save(); }
private void highlight(String s) { DefaultInputFile inputFile = TestInputFileBuilder.create("moduleKey", file.getName()) .setLanguage("php") .setType(Type.MAIN) .initMetadata(s) .build(); fileSystem.add(inputFile); context = SensorContextTester.create(tempFolder.getRoot()); NewHighlighting highlighting = context.newHighlighting().onFile(inputFile); Tree tree = PARSER.parse(s); SyntaxHighlighterVisitor.highlight(tree, highlighting); highlighting.save(); }