diff options
Diffstat (limited to 'src/test/java/org/javacs')
-rw-r--r-- | src/test/java/org/javacs/FindReferencesTest.java | 6 | ||||
-rw-r--r-- | src/test/java/org/javacs/GotoTest.java | 48 | ||||
-rw-r--r-- | src/test/java/org/javacs/JavaCompilerServiceTest.java | 43 |
3 files changed, 34 insertions, 63 deletions
diff --git a/src/test/java/org/javacs/FindReferencesTest.java b/src/test/java/org/javacs/FindReferencesTest.java index 9ce21c7..e728cc9 100644 --- a/src/test/java/org/javacs/FindReferencesTest.java +++ b/src/test/java/org/javacs/FindReferencesTest.java @@ -37,6 +37,12 @@ public class FindReferencesTest { } @Test + public void findInterfaceReference() { + assertThat( + items("/org/javacs/example/GotoImplementation.java", 14, 26), contains("GotoImplementation.java(5)")); + } + + @Test public void findConstructorReferences() { assertThat(items("/org/javacs/example/ConstructorRefs.java", 4, 10), contains("ConstructorRefs.java(9)")); } diff --git a/src/test/java/org/javacs/GotoTest.java b/src/test/java/org/javacs/GotoTest.java index 7ad39ea..ac5d1cc 100644 --- a/src/test/java/org/javacs/GotoTest.java +++ b/src/test/java/org/javacs/GotoTest.java @@ -10,6 +10,7 @@ import org.javacs.lsp.*; import org.junit.Ignore; import org.junit.Test; +// TODO change :n to (n) public class GotoTest { private static final String file = "/org/javacs/example/Goto.java"; private static final String defaultConstructorFile = "/org/javacs/example/GotoDefaultConstructor.java"; @@ -18,91 +19,91 @@ public class GotoTest { public void localVariable() { var suggestions = doGoto(file, 10, 9); - assertThat(suggestions, contains("Goto.java:5")); + assertThat(suggestions, hasItem("Goto.java:5")); } @Test public void defaultConstructor() { var suggestions = doGoto(defaultConstructorFile, 5, 46); - assertThat(suggestions, contains("GotoDefaultConstructor.java:3")); + assertThat(suggestions, hasItem("GotoDefaultConstructor.java:3")); } @Test public void constructor() { var suggestions = doGoto(file, 11, 21); - assertThat(suggestions, contains("Goto.java:3")); + assertThat(suggestions, hasItem("Goto.java:3")); } @Test public void className() { var suggestions = doGoto(file, 16, 9); - assertThat(suggestions, contains("Goto.java:3")); + assertThat(suggestions, hasItem("Goto.java:3")); } @Test public void staticField() { var suggestions = doGoto(file, 13, 22); - assertThat(suggestions, contains("Goto.java:36")); + assertThat(suggestions, hasItem("Goto.java:36")); } @Test public void field() { var suggestions = doGoto(file, 14, 22); - assertThat(suggestions, contains("Goto.java:37")); + assertThat(suggestions, hasItem("Goto.java:37")); } @Test public void staticMethod() { var suggestions = doGoto(file, 16, 14); - assertThat(suggestions, contains("Goto.java:38")); + assertThat(suggestions, hasItem("Goto.java:38")); } @Test public void method() { var suggestions = doGoto(file, 17, 14); - assertThat(suggestions, contains("Goto.java:41")); + assertThat(suggestions, hasItem("Goto.java:41")); } @Test public void staticMethodReference() { var suggestions = doGoto(file, 19, 27); - assertThat(suggestions, contains("Goto.java:38")); + assertThat(suggestions, hasItem("Goto.java:38")); } @Test public void methodReference() { var suggestions = doGoto(file, 20, 27); - assertThat(suggestions, contains("Goto.java:41")); + assertThat(suggestions, hasItem("Goto.java:41")); } @Test public void otherStaticMethod() { var suggestions = doGoto(file, 29, 25); - assertThat(suggestions, contains(startsWith("GotoOther.java:"))); + assertThat(suggestions, hasItem(startsWith("GotoOther.java:"))); } @Test public void otherMethod() { var suggestions = doGoto(file, 30, 18); - assertThat(suggestions, contains(startsWith("GotoOther.java:"))); + assertThat(suggestions, hasItem(startsWith("GotoOther.java:"))); } @Test public void otherCompiledFile() { var suggestions = doGoto(file, 29, 25); - assertThat(suggestions, contains(startsWith("GotoOther.java:"))); + assertThat(suggestions, hasItem(startsWith("GotoOther.java:"))); } @Test @@ -110,7 +111,7 @@ public class GotoTest { public void typeParam() { var suggestions = doGoto(file, 46, 12); - assertThat(suggestions, contains("Goto.java:3")); + assertThat(suggestions, hasItem("Goto.java:3")); } @Test @@ -125,18 +126,25 @@ public class GotoTest { public void gotoOverload() { String file = "/org/javacs/example/GotoOverload.java"; - assertThat(doGoto(file, 7, 12), contains("GotoOverload.java:4")); - assertThat(doGoto(file, 8, 12), contains("GotoOverload.java:12")); - assertThat(doGoto(file, 9, 12), contains("GotoOverload.java:16")); + assertThat(doGoto(file, 7, 12), hasItem("GotoOverload.java:4")); + assertThat(doGoto(file, 8, 12), hasItem("GotoOverload.java:12")); + assertThat(doGoto(file, 9, 12), hasItem("GotoOverload.java:16")); } @Test public void gotoOverloadInOtherFile() { String file = "/org/javacs/example/GotoOverloadInOtherFile.java"; - assertThat(doGoto(file, 5, 25), contains("GotoOverload.java:4")); - assertThat(doGoto(file, 6, 25), contains("GotoOverload.java:12")); - assertThat(doGoto(file, 7, 25), contains("GotoOverload.java:16")); + assertThat(doGoto(file, 5, 25), hasItem("GotoOverload.java:4")); + assertThat(doGoto(file, 6, 25), hasItem("GotoOverload.java:12")); + assertThat(doGoto(file, 7, 25), hasItem("GotoOverload.java:16")); + } + + @Test + public void gotoImplementation() { + String file = "/org/javacs/example/GotoImplementation.java"; + + assertThat(doGoto(file, 5, 18), hasItems("GotoImplementation.java:9", "GotoImplementation.java:14")); } private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer(); diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java index 0785acb..c947bde 100644 --- a/src/test/java/org/javacs/JavaCompilerServiceTest.java +++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java @@ -226,49 +226,6 @@ public class JavaCompilerServiceTest { assertThat(names, hasItem("concurrent")); } - /* - @Test - public void gotoDefinition() { - var def = - compiler.definition("/GotoDefinition.java"; - assertTrue(def.isPresent()); - - var t = def.get(); - var unit = t.getCompilationUnit(); - assertThat(unit.getSourceFile().getName(), endsWith("GotoDefinition.java")); - - var trees = compiler.trees(); - var pos = trees.getSourcePositions(); - var lines = unit.getLineMap(); - long start = pos.getStartPosition(unit, t.getLeaf()); - long line = lines.getLineNumber(start); - assertThat(line, equalTo(6L)); - } - */ - - @Test - public void references() { - var file = "GotoDefinition.java"; - var to = compiler.compileFocus(resourceUri(file), contents(file), 6, 13).element(); - var possible = compiler.potentialReferences(to); - assertThat( - "GotoDefinition.java can have references to itself", - possible, - hasItem(hasToString(endsWith("/GotoDefinition.java")))); - - var batch = compiler.compileBatch(possible); - var refs = batch.references(to); - var stringify = new ArrayList<String>(); - for (var r : refs) { - var uri = r.getCompilationUnit().getSourceFile().toUri(); - var fileName = Paths.get(uri).getFileName(); - var range = batch.range(r).get(); - stringify.add(String.format("%s:%d", fileName, range.start.line + 1)); - } - assertThat(stringify, hasItem("GotoDefinition.java:3")); - assertThat(stringify, not(hasItem("GotoDefinition.java:6"))); - } - @Test public void overloads() { var uri = resourceUri("Overloads.java"); |