@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 public void testExecution() throws IOException { File symbol = new File(baseDir, "src/foo.xoo.highlighting"); FileUtils.write(symbol, "1:4:k\n12:15:cd\n\n#comment"); DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") .setLanguage("xoo") .setModuleBaseDir(baseDir.toPath()) .initMetadata(" xoo\nazertyazer\nfoo") .build(); context.fileSystem().add(inputFile); sensor.execute(context); assertThat(context.highlightingTypeAt("foo:src/foo.xoo", 1, 2)).containsOnly(TypeOfText.KEYWORD); assertThat(context.highlightingTypeAt("foo:src/foo.xoo", 2, 8)).containsOnly(TypeOfText.COMMENT); } }
private void assertHighlighting(String componentKey, int line, int columnFirst, int columnLast, @Nullable TypeOfText type) { for (int column = columnFirst; column <= columnLast; column++) { List<TypeOfText> typeOfTexts = sensorContext.highlightingTypeAt(componentKey, line, column - 1); if (type != null) { assertThat(typeOfTexts).as("Expect highlighting " + type + " at line " + line + " lineOffset " + column).containsExactly(type); } else { assertThat(typeOfTexts).as("Expect no highlighting at line " + line + " lineOffset " + column).containsExactly(); } } }
private void checkInternal(int line, int column, String messageComplement, TypeOfText expectedTypeOfText) { String componentKey = "moduleKey:" + file.getName(); List<TypeOfText> foundTypeOfTexts = context.highlightingTypeAt(componentKey, line, column); int expectedNumberOfTypeOfText = expectedTypeOfText == null ? 0 : 1; String message = "number of TypeOfTexts at line " + line + " and column " + column + messageComplement; assertThat(foundTypeOfTexts).as(message).hasSize(expectedNumberOfTypeOfText); if (expectedNumberOfTypeOfText > 0) { message = "found TypeOfTexts at line " + line + " and column " + column + messageComplement; assertThat(foundTypeOfTexts.get(0)).as(message).isEqualTo(expectedTypeOfText); } }
private void checkInternal(SensorContextTester context, int line, int column, String messageComplement, TypeOfText expectedTypeOfText) { List<TypeOfText> foundTypeOfTexts = context.highlightingTypeAt(componentKey, line, column); int expectedNumberOfTypeOfText = expectedTypeOfText == null ? 0 : 1; String message = "number of TypeOfTexts at line " + line + " and column " + column + messageComplement; assertThat(foundTypeOfTexts).as(message).hasSize(expectedNumberOfTypeOfText); if (expectedNumberOfTypeOfText > 0) { message = "found TypeOfTexts at line " + line + " and column " + column + messageComplement; assertThat(foundTypeOfTexts.get(0)).as(message).isEqualTo(expectedTypeOfText); } }
@Test public void empty_input() throws Exception { highlight("<?php "); assertThat(context.highlightingTypeAt("moduleKey:" + file.getName(), 1, 0)).isEmpty(); }
@Test public void test_execute() { inputFile("file1.pl"); sensor().execute(context); String key = "moduleKey:file1.pl"; String msg = "number of TypeOfText for the highlighting of keyword 'sub'"; assertThat(context.highlightingTypeAt(key, 9, 2)).as(msg).hasSize(1); assertThat(context.allAnalysisErrors()).isEmpty(); }