summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-31 17:40:45 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-31 17:40:45 -0800
commitc1a2ec0e932a4d0c35012bee5e9844b1ce8d3332 (patch)
tree16405b15420d28cc6d9533a53db2d757eea02965 /src/test
parent9c8b908f5f4b2395a14652a9fcf3a2a20006e621 (diff)
downloadjava-language-server-c1a2ec0e932a4d0c35012bee5e9844b1ce8d3332.zip
Invalidate indexes when targets change
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/javacs/CodeLensTest.java19
-rw-r--r--src/test/java/org/javacs/FindResource.java14
-rw-r--r--src/test/java/org/javacs/JavaCompilerServiceTest.java13
3 files changed, 31 insertions, 15 deletions
diff --git a/src/test/java/org/javacs/CodeLensTest.java b/src/test/java/org/javacs/CodeLensTest.java
index 441bb30..0185b73 100644
--- a/src/test/java/org/javacs/CodeLensTest.java
+++ b/src/test/java/org/javacs/CodeLensTest.java
@@ -61,8 +61,8 @@ public class CodeLensTest {
assertThat(lenses, not(empty()));
var titles = titles(lenses);
- assertThat(titles, hasItem("4:1 references"));
- assertThat(titles, hasItem("6:1 references"));
+ assertThat(titles, hasItem("4:1 reference"));
+ assertThat(titles, hasItem("6:1 reference"));
}
@Test
@@ -71,4 +71,19 @@ public class CodeLensTest {
var titles = titles(lenses);
assertThat(titles, not(hasItem("4:0 references")));
}
+
+ @Test
+ public void signatureMatches() {
+ var file = "/org/javacs/example/ConstructorRefs.java";
+ var uri = FindResource.uri(file);
+ var contents = FindResource.contents(file);
+ var compile = server.compiler.compileFile(uri, contents);
+ var signatureMatches = compile.signatureMatches();
+
+ var good = List.of(new Ptr("org.javacs.example.ConstructorRefs.ConstructorRefs(int)"));
+ assertTrue(signatureMatches.test(good));
+
+ var bad = List.of(new Ptr("org.javacs.example.ConstructorRefs.ConstructorRefs(int, int)"));
+ assertFalse(signatureMatches.test(bad));
+ }
}
diff --git a/src/test/java/org/javacs/FindResource.java b/src/test/java/org/javacs/FindResource.java
index ce07a04..6e6860e 100644
--- a/src/test/java/org/javacs/FindResource.java
+++ b/src/test/java/org/javacs/FindResource.java
@@ -1,8 +1,11 @@
package org.javacs;
+import java.io.IOException;
import java.net.URI;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.List;
/** Find java sources in test-project/workspace/src */
public class FindResource {
@@ -12,6 +15,17 @@ public class FindResource {
return path.toUri();
}
+ public static String contents(String resourcePath) {
+ var path = path(resourcePath);
+ List<String> lines;
+ try {
+ lines = Files.readAllLines(path);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return String.join("\n", lines);
+ }
+
public static Path path(String resourcePath) {
if (resourcePath.startsWith("/")) resourcePath = resourcePath.substring(1);
diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java
index 31339c9..db694b5 100644
--- a/src/test/java/org/javacs/JavaCompilerServiceTest.java
+++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java
@@ -10,7 +10,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.StringJoiner;
@@ -268,18 +267,6 @@ public class JavaCompilerServiceTest {
}
@Test
- public void countReferences() {
- var file = "GotoDefinition.java";
- var refs = compiler.countReferences(resourceUri(file), contents(file), ReportProgress.EMPTY);
- var stringify = new HashMap<String, Integer>();
- for (var kv : refs.entrySet()) {
- var key = kv.getKey().toString();
- stringify.put(key, kv.getValue());
- }
- assertThat(stringify, hasEntry("GotoDefinition.goToHere()", 1));
- }
-
- @Test
public void overloads() {
var uri = resourceUri("Overloads.java");
var contents = contents("Overloads.java");