diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/javacs/BenchmarkPruner.java | 7 | ||||
-rw-r--r-- | src/test/java/org/javacs/CodeLensTest.java | 3 | ||||
-rw-r--r-- | src/test/java/org/javacs/JavaCompilerServiceTest.java | 49 | ||||
-rw-r--r-- | src/test/java/org/javacs/PrunerTest.java | 10 | ||||
-rw-r--r-- | src/test/java/org/javacs/PtrTest.java | 3 |
5 files changed, 29 insertions, 43 deletions
diff --git a/src/test/java/org/javacs/BenchmarkPruner.java b/src/test/java/org/javacs/BenchmarkPruner.java index 9ad432a..56922a5 100644 --- a/src/test/java/org/javacs/BenchmarkPruner.java +++ b/src/test/java/org/javacs/BenchmarkPruner.java @@ -24,11 +24,12 @@ public class BenchmarkPruner { while (it.hasNext()) { var file = it.next(); if (!Files.isRegularFile(file)) continue; - var contents = String.join("\n", Files.readAllLines(file)); if (prune) { - contents = Pruner.prune(file.toUri(), contents, "isWord"); + var contents = Pruner.prune(file.toUri(), "isWord"); + files.add(new SourceFileObject(file, contents)); + } else { + files.add(new SourceFileObject(file)); } - files.add(new SourceFileObject(file, contents)); } return files; } catch (IOException e) { diff --git a/src/test/java/org/javacs/CodeLensTest.java b/src/test/java/org/javacs/CodeLensTest.java index 61b8095..48f8803 100644 --- a/src/test/java/org/javacs/CodeLensTest.java +++ b/src/test/java/org/javacs/CodeLensTest.java @@ -76,8 +76,7 @@ public class CodeLensTest { 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 compile = server.compiler.compileFile(uri); var signatureMatches = compile.signatureMatches(); var good = List.of(new Ptr("org.javacs.example/ConstructorRefs#<init>(int)")); diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java index dde1569..9b6c2ee 100644 --- a/src/test/java/org/javacs/JavaCompilerServiceTest.java +++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java @@ -53,8 +53,7 @@ public class JavaCompilerServiceTest { @Test public void element() { var uri = resourceUri("HelloWorld.java"); - var contents = contents("HelloWorld.java"); - var found = compiler.compileFocus(uri, contents, 3, 24).element(); + var found = compiler.compileFocus(uri, 3, 24).element(); assertThat(found.getSimpleName(), hasToString(containsString("println"))); } @@ -62,8 +61,7 @@ public class JavaCompilerServiceTest { @Test public void elementWithError() { var uri = resourceUri("CompleteMembers.java"); - var contents = contents("CompleteMembers.java"); - var found = compiler.compileFocus(uri, contents, 3, 12).element(); + var found = compiler.compileFocus(uri, 3, 12).element(); assertThat(found, notNullValue()); } @@ -87,8 +85,7 @@ public class JavaCompilerServiceTest { @Test public void identifiers() { var uri = resourceUri("CompleteIdentifiers.java"); - var contents = contents("CompleteIdentifiers.java"); - var focus = compiler.compileFocus(uri, contents, 13, 21); + var focus = compiler.compileFocus(uri, 13, 21); var found = focus.scopeMembers("complete"); var names = elementNames(found); assertThat(names, hasItem("completeLocal")); @@ -105,8 +102,7 @@ public class JavaCompilerServiceTest { @Test public void identifiersInMiddle() { var uri = resourceUri("CompleteInMiddle.java"); - var contents = contents("CompleteInMiddle.java"); - var focus = compiler.compileFocus(uri, contents, 13, 21); + var focus = compiler.compileFocus(uri, 13, 21); var found = focus.scopeMembers("complete"); var names = elementNames(found); assertThat(names, hasItem("completeLocal")); @@ -123,9 +119,8 @@ public class JavaCompilerServiceTest { @Test public void completeIdentifiers() { var uri = resourceUri("CompleteIdentifiers.java"); - var contents = contents("CompleteIdentifiers.java"); - var ctx = compiler.parseFile(uri, contents).completionContext(13, 21).get(); - var focus = compiler.compileFocus(uri, contents, ctx.line, ctx.character); + var ctx = compiler.parseFile(uri).completionContext(13, 21).get(); + var focus = compiler.compileFocus(uri, ctx.line, ctx.character); var found = focus.completeIdentifiers(ctx.inClass, ctx.inMethod, ctx.partialName); var names = completionNames(found); assertThat(names, hasItem("completeLocal")); @@ -142,8 +137,7 @@ public class JavaCompilerServiceTest { @Test public void members() { var uri = resourceUri("CompleteMembers.java"); - var contents = contents("CompleteMembers.java"); - var focus = compiler.compileFocus(uri, contents, 3, 14); + var focus = compiler.compileFocus(uri, 3, 14); var found = focus.completeMembers(false); var names = completionNames(found); assertThat(names, hasItem("subMethod")); @@ -154,9 +148,8 @@ public class JavaCompilerServiceTest { @Test public void completeMembers() { var uri = resourceUri("CompleteMembers.java"); - var contents = contents("CompleteMembers.java"); - var ctx = compiler.parseFile(uri, contents).completionContext(3, 15).get(); - var focus = compiler.compileFocus(uri, contents, ctx.line, ctx.character); + var ctx = compiler.parseFile(uri).completionContext(3, 15).get(); + var focus = compiler.compileFocus(uri, ctx.line, ctx.character); var found = focus.completeMembers(false); var names = completionNames(found); assertThat(names, hasItem("subMethod")); @@ -167,9 +160,8 @@ public class JavaCompilerServiceTest { @Test public void completeExpression() { var uri = resourceUri("CompleteExpression.java"); - var contents = contents("CompleteExpression.java"); - var ctx = compiler.parseFile(uri, contents).completionContext(3, 37).get(); - var focus = compiler.compileFocus(uri, contents, ctx.line, ctx.character); + var ctx = compiler.parseFile(uri).completionContext(3, 37).get(); + var focus = compiler.compileFocus(uri, ctx.line, ctx.character); var found = focus.completeMembers(false); var names = completionNames(found); assertThat(names, hasItem("instanceMethod")); @@ -180,9 +172,8 @@ public class JavaCompilerServiceTest { @Test public void completeClass() { var uri = resourceUri("CompleteClass.java"); - var contents = contents("CompleteClass.java"); - var ctx = compiler.parseFile(uri, contents).completionContext(3, 23).get(); - var focus = compiler.compileFocus(uri, contents, ctx.line, ctx.character); + var ctx = compiler.parseFile(uri).completionContext(3, 23).get(); + var focus = compiler.compileFocus(uri, ctx.line, ctx.character); var found = focus.completeMembers(false); var names = completionNames(found); assertThat(names, hasItems("staticMethod", "staticField")); @@ -194,9 +185,8 @@ public class JavaCompilerServiceTest { @Test public void completeImports() { var uri = resourceUri("CompleteImports.java"); - var contents = contents("CompleteImports.java"); - var ctx = compiler.parseFile(uri, contents).completionContext(1, 18).get(); - var focus = compiler.compileFocus(uri, contents, ctx.line, ctx.character); + var ctx = compiler.parseFile(uri).completionContext(1, 18).get(); + var focus = compiler.compileFocus(uri, ctx.line, ctx.character); var found = focus.completeMembers(false); var names = completionNames(found); assertThat(names, hasItem("List")); @@ -206,8 +196,7 @@ public class JavaCompilerServiceTest { @Test public void overloads() { var uri = resourceUri("Overloads.java"); - var contents = contents("Overloads.java"); - var found = compiler.compileFocus(uri, contents, 3, 15).methodInvocation().get(); + var found = compiler.compileFocus(uri, 3, 15).methodInvocation().get(); var strings = found.overloads.stream().map(Object::toString).collect(Collectors.toList()); assertThat(strings, hasItem(containsString("print(int)"))); @@ -259,8 +248,7 @@ public class JavaCompilerServiceTest { @Test public void localDoc() { var uri = resourceUri("LocalMethodDoc.java"); - var contents = contents("LocalMethodDoc.java"); - var method = compiler.compileFocus(uri, contents, 3, 21).methodInvocation().get().activeMethod.get(); + var method = compiler.compileFocus(uri, 3, 21).methodInvocation().get().activeMethod.get(); var ptr = new Ptr(method); var file = compiler.docs().find(ptr).get(); var parse = compiler.docs().parse(file); @@ -272,8 +260,7 @@ public class JavaCompilerServiceTest { @Test public void fixImports() { var uri = resourceUri("MissingImport.java"); - var contents = contents("MissingImport.java"); - var qualifiedNames = compiler.compileFile(uri, contents).fixImports(); + var qualifiedNames = compiler.compileFile(uri).fixImports(); assertThat(qualifiedNames, hasItem("java.util.List")); } diff --git a/src/test/java/org/javacs/PrunerTest.java b/src/test/java/org/javacs/PrunerTest.java index 9d649c2..3b6f017 100644 --- a/src/test/java/org/javacs/PrunerTest.java +++ b/src/test/java/org/javacs/PrunerTest.java @@ -10,35 +10,35 @@ public class PrunerTest { @Test public void pruneMethods() { - var actual = Pruner.prune(resourceUri("PruneMethods.java"), contents("PruneMethods.java"), 6, 19); + var actual = Pruner.prune(resourceUri("PruneMethods.java"), 6, 19); var expected = contents("PruneMethods_erased.java"); assertThat(actual, equalToIgnoringWhiteSpace(expected)); } @Test public void pruneToEndOfBlock() { - var actual = Pruner.prune(resourceUri("PruneToEndOfBlock.java"), contents("PruneToEndOfBlock.java"), 4, 18); + var actual = Pruner.prune(resourceUri("PruneToEndOfBlock.java"), 4, 18); var expected = contents("PruneToEndOfBlock_erased.java"); assertThat(actual, equalToIgnoringWhiteSpace(expected)); } @Test public void pruneMiddle() { - var actual = Pruner.prune(resourceUri("PruneMiddle.java"), contents("PruneMiddle.java"), 4, 12); + var actual = Pruner.prune(resourceUri("PruneMiddle.java"), 4, 12); var expected = contents("PruneMiddle_erased.java"); assertThat(actual, equalToIgnoringWhiteSpace(expected)); } @Test public void pruneDot() { - var actual = Pruner.prune(resourceUri("PruneDot.java"), contents("PruneDot.java"), 3, 11); + var actual = Pruner.prune(resourceUri("PruneDot.java"), 3, 11); var expected = contents("PruneDot_erased.java"); assertThat(actual, equalToIgnoringWhiteSpace(expected)); } @Test public void pruneWords() { - var actual = Pruner.prune(resourceUri("PruneWords.java"), contents("PruneWords.java"), "word"); + var actual = Pruner.prune(resourceUri("PruneWords.java"), "word"); var expected = contents("PruneWords_erased.java"); assertThat(actual, equalToIgnoringWhiteSpace(expected)); } diff --git a/src/test/java/org/javacs/PtrTest.java b/src/test/java/org/javacs/PtrTest.java index 8dcf110..379df59 100644 --- a/src/test/java/org/javacs/PtrTest.java +++ b/src/test/java/org/javacs/PtrTest.java @@ -11,8 +11,7 @@ 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); + static CompileFile compile = server.compiler.compileFile(uri); @Test public void classPtr() { |