@Test public void testSymbolReferences() { assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull(); NewSymbolTable symbolTable = tester.newSymbolTable() .onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()); symbolTable .newSymbol(1, 8, 1, 10); symbolTable .newSymbol(1, 1, 1, 5) .newReference(6, 9) .newReference(1, 10, 1, 13); symbolTable.save(); assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull(); assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 8)).isEmpty(); assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 3)).extracting("start.line", "start.lineOffset", "end.line", "end.lineOffset").containsExactly(tuple(1, 6, 1, 9), tuple(1, 10, 1, 13)); }
@Test public void testExecution() throws IOException { File symbol = new File(baseDir, "src/foo.xoo.symbol"); FileUtils.write(symbol, "1:4,7\n12:15,23:33\n\n#comment"); InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") .initMetadata("xoo file with some source code and length over 33") .setLanguage(Xoo.KEY) .setModuleBaseDir(baseDir.toPath()) .build(); context.fileSystem().add(inputFile); sensor.execute(context); assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 2)) .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1,10))); assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 13)) .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 23), new DefaultTextPointer(1,33))); }
/** * Checks the existence of a symbol at the specified location. * @param line the line of the symbol * @param column any column of the symbol */ public void checkSymbolExistence(SensorContextTester context, int line, int column) { Collection<TextRange> foundReferences = context.referencesForSymbolAt(componentKey, line, column); String message = "a symbol is expected to exist and have references at line " + line + " and column " + column; assertThat(foundReferences).as(message).isNotNull(); }
public void checkNoSymbolExists(SensorContextTester context, int line, int column) { Collection<TextRange> foundReferences = context.referencesForSymbolAt(componentKey, line, column); String message = "no symbol is expected to exist at line " + line + " and column " + column; assertThat(foundReferences).as(message).isNull(); }
/** * Checks that the specified symbol references match with the symbol references of the specified symbol. * @param line the line of the symbol * @param column any column of the symbol * @param referenceRanges all references to the symbol */ public void checkSymbolReferences(SensorContextTester context, int line, int column, List<? extends TextRange> referenceRanges) { Collection<TextRange> foundReferences = context.referencesForSymbolAt(componentKey, line, column); String message = "number of found references to the symbol located at line " + line + " and column " + column; assertThat(foundReferences.size()).as(message).isEqualTo(referenceRanges.size()); for (TextRange referenceRange : referenceRanges) { assertThat(foundReferences).extracting("start", "end").contains(tuple(referenceRange.start(), referenceRange.end())); } }