summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2019-01-01 13:56:18 -0800
committerGeorge Fraser <george@fivetran.com>2019-01-01 13:56:18 -0800
commitc1e61a96093a879bcb907f69787223127d53027f (patch)
treee99ae267a3ffbca5f179ff60392c5fe5005461cc /src/test/java
parent27aa558c7549d4bb91dbfb63744c0d2e64484d16 (diff)
downloadjava-language-server-c1e61a96093a879bcb907f69787223127d53027f.zip
Make Ptr more precies
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/javacs/CodeLensTest.java4
-rw-r--r--src/test/java/org/javacs/DocsTest.java26
-rw-r--r--src/test/java/org/javacs/JavaCompilerServiceTest.java7
-rw-r--r--src/test/java/org/javacs/PtrTest.java116
4 files changed, 141 insertions, 12 deletions
diff --git a/src/test/java/org/javacs/CodeLensTest.java b/src/test/java/org/javacs/CodeLensTest.java
index 0185b73..893c605 100644
--- a/src/test/java/org/javacs/CodeLensTest.java
+++ b/src/test/java/org/javacs/CodeLensTest.java
@@ -80,10 +80,10 @@ public class CodeLensTest {
var compile = server.compiler.compileFile(uri, contents);
var signatureMatches = compile.signatureMatches();
- var good = List.of(new Ptr("org.javacs.example.ConstructorRefs.ConstructorRefs(int)"));
+ var good = List.of(new Ptr("org.javacs.example/ConstructorRefs#<init>(int)"));
assertTrue(signatureMatches.test(good));
- var bad = List.of(new Ptr("org.javacs.example.ConstructorRefs.ConstructorRefs(int, int)"));
+ var bad = List.of(new Ptr("org.javacs.example/ConstructorRefs#<init>(int,int)"));
assertFalse(signatureMatches.test(bad));
}
}
diff --git a/src/test/java/org/javacs/DocsTest.java b/src/test/java/org/javacs/DocsTest.java
index dd89e46..6819974 100644
--- a/src/test/java/org/javacs/DocsTest.java
+++ b/src/test/java/org/javacs/DocsTest.java
@@ -11,24 +11,34 @@ public class DocsTest {
public void classDoc() {
var sourcePath = Set.of(JavaCompilerServiceTest.simpleProjectSrc());
var docs = new Docs(sourcePath);
- var tree = docs.classDoc("ClassDoc");
- assertTrue(tree.isPresent());
- assertThat(tree.get().getFirstSentence(), hasToString("A great class"));
+ var ptr = new Ptr("ClassDoc");
+ var file = docs.find(ptr).get();
+ var parse = docs.parse(file);
+ var path = parse.fuzzyFind(ptr).get();
+ var tree = parse.doc(path);
+ assertThat(tree.getFirstSentence(), hasToString("A great class"));
}
@Test
public void memberDoc() {
var sourcePath = Set.of(JavaCompilerServiceTest.simpleProjectSrc());
var docs = new Docs(sourcePath);
- var tree = docs.memberDoc("LocalMethodDoc", "targetMethod");
- assertTrue(tree.isPresent());
- assertThat(tree.get().getFirstSentence(), hasToString("A great method"));
+ var ptr = new Ptr("LocalMethodDoc#targetMethod(int)");
+ var file = docs.find(ptr).get();
+ var parse = docs.parse(file);
+ var path = parse.fuzzyFind(ptr).get();
+ var tree = parse.doc(path);
+ assertThat(tree.getFirstSentence(), hasToString("A great method"));
}
@Test
public void platformDoc() {
var docs = new Docs(Set.of());
- var tree = docs.classDoc("java.util.List");
- assertTrue(tree.isPresent());
+ var ptr = new Ptr("java.util/List");
+ var file = docs.find(ptr).get();
+ var parse = docs.parse(file);
+ var path = parse.fuzzyFind(ptr).get();
+ var tree = parse.doc(path);
+ assertThat(tree.getFirstSentence(), not(empty()));
}
}
diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java
index db694b5..838d9b5 100644
--- a/src/test/java/org/javacs/JavaCompilerServiceTest.java
+++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java
@@ -290,8 +290,11 @@ public class JavaCompilerServiceTest {
var uri = resourceUri("LocalMethodDoc.java");
var contents = contents("LocalMethodDoc.java");
var method = compiler.compileFocus(uri, contents, 3, 21).methodInvocation().get().activeMethod.get();
- var doc = compiler.docs().methodDoc(method);
- assertTrue(doc.isPresent());
+ var ptr = new Ptr(method);
+ var file = compiler.docs().find(ptr).get();
+ var parse = compiler.docs().parse(file);
+ var path = parse.fuzzyFind(ptr).get();
+ var doc = parse.doc(path);
assertThat(doc.toString(), containsString("A great method"));
}
diff --git a/src/test/java/org/javacs/PtrTest.java b/src/test/java/org/javacs/PtrTest.java
new file mode 100644
index 0000000..8dcf110
--- /dev/null
+++ b/src/test/java/org/javacs/PtrTest.java
@@ -0,0 +1,116 @@
+package org.javacs;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import org.junit.Test;
+
+public class PtrTest {
+
+ static JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
+ static String file = "/org/javacs/example/Ptrs.java";
+ static URI uri = FindResource.uri(file);
+ static String contents = FindResource.contents(file);
+ static CompileFile compile = server.compiler.compileFile(uri, contents);
+
+ @Test
+ public void classPtr() {
+ var el = compile.element(3, 15).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void fieldPtr() {
+ var el = compile.element(4, 20).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#field"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void emptyMethodPtr() {
+ var el = compile.element(6, 20).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#method()"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void intMethodPtr() {
+ var el = compile.element(8, 20).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#method(int)"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void stringMethodPtr() {
+ var el = compile.element(10, 20).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#method(java.lang.String)"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void constructorPtr() {
+ var el = compile.element(12, 13).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs#<init>(int)"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void innerClassPtr() {
+ var el = compile.element(14, 20).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void innerFieldPtr() {
+ var el = compile.element(15, 20).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass#innerField"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void innerEmptyMethodPtr() {
+ var el = compile.element(17, 25).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass#innerMethod()"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+
+ @Test
+ public void innerConstructorPtr() {
+ var el = compile.element(19, 21).get();
+ var ptr = new Ptr(el);
+ assertThat(ptr.toString(), equalTo("org.javacs.example/Ptrs.InnerClass#<init>()"));
+
+ var copy = new Ptr(ptr.toString());
+ assertThat(copy, equalTo(ptr));
+ }
+}