@Test public void testEmptyWorkspace() throws InterruptedException, ExecutionException, IOException { GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); }
@Before public void setup() throws IOException { workspaceRoot = tempFolder.newFolder(); Path changedOutput = tempFolder.newFolder().toPath(); Path target = tempFolder.newFolder().toPath(); uriSupplier = new WorkspaceUriSupplier(workspaceRoot.toPath(), changedOutput); parser = GroovyTreeParser.of(() -> { GroovyWorkspaceCompiler compiler = GroovyWorkspaceCompiler.of(target, workspaceRoot.toPath(), changedOutput); assertEquals(Sets.newHashSet(), compiler.compile(ImmutableSet.of())); return compiler.get(); }, workspaceRoot.toPath(), uriSupplier); }
@Test public void testCompile_WithJavaExtensionError() throws InterruptedException, ExecutionException, IOException { File test = addFileToFolder(root.getRoot(), "Test.java", "public class Test {" + "Foo foo;" + "}"); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); Set<PublishDiagnosticsParams> diagnostics = compiler.compile(ImmutableSet.of()); assertEquals(Sets.newHashSet(new PublishDiagnosticsParams( test.toPath().toUri().toString(), ImmutableList.of(new Diagnostic(Ranges.createRange(0, 19, 0, 26), "unable to resolve class Foo \n @ line 1, column 20.", DiagnosticSeverity.Error, GroovyConstants.GROOVY_COMPILER)))), diagnostics); }
@Test public void testHandleChangeWatchedFiles_deleted() throws IOException { File newFolder1 = root.newFolder(); File catFile = addFileToFolder(newFolder1, "Cat.groovy", "class Cat {\n" + "}\n"); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); // Compile assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); // Assert the original file is in the compilation unit assertSingleSourceFileUri(catFile, compiler.get().iterator()); // Delete the file assertThat(catFile.delete()).isTrue(); // Call handleChangeWatchedFile with a change saying this file has been deleted outside this language server compiler.handleChangeWatchedFiles(Lists.newArrayList( new FileEvent( root.getRoot().toPath().relativize(catFile.toPath()).toString(), FileChangeType.Changed))); // Re-compile assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); // Assert the compiler has no source units assertThat(compiler.get().iterator().hasNext()).isFalse(); }
@Test public void testCompile_WithJavaExtensionAndGroovySyntax() throws InterruptedException, ExecutionException, IOException { addFileToFolder(root.getRoot(), "ExceptionNewNotSameName.java", "public class ExceptionNew {}"); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); }
@Test public void testHandleChangeWatchedFiles_created() throws IOException { File newFolder1 = root.newFolder(); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); // Compile assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); // Assert the compiler has no source units assertThat(compiler.get().iterator().hasNext()).isFalse(); File catFile = addFileToFolder(newFolder1, "Cat.groovy", "class Cat {\n" + "}\n"); // Call handleChangeWatchedFile with a change saying this file has been changed outside this language server compiler.handleChangeWatchedFiles(Lists.newArrayList( new FileEvent( root.getRoot().toPath().relativize(catFile.toPath()).toString(), FileChangeType.Created))); // Re-compile assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); // Assert the compilation unit now contains cat file assertSingleSourceFileUri(catFile, compiler.get().iterator()); }
GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); Lists.newArrayList(new TextDocumentContentChangeEvent(Ranges.createRange(0, 6, 0, 9), 3, "Dog"))); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); .isFalse(); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of()));
@Test public void testCompile_WithJavaExtension() throws InterruptedException, ExecutionException, IOException { addFileToFolder(root.getRoot(), "test1.groovy", "class Coordinates {\n" + " double latitude\n" + " double longitude\n" + " double getAt(int idx) {\n" + " if (idx == 0) latitude\n" + " else if (idx == 1) longitude\n" + " else throw new ExceptionNew(\"Wrong coordinate index, use 0 or 1\")\n" + " }\n" + "}\n"); addFileToFolder(root.getRoot(), "ExceptionNew.java", "public class ExceptionNew {}"); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); }
@Test public void testCompile_withExtraFiles() throws InterruptedException, ExecutionException, IOException { File newFolder1 = root.newFolder(); File newFolder2 = root.newFolder(); addFileToFolder(newFolder1, "coordinates.groovy", "class Coordinates {\n" + " double latitude\n" + " double longitude\n" + " double getAt(int idx) {\n" + " if (idx == 0) latitude\n" + " else if (idx == 1) longitude\n" + " else throw new Exception(\"Wrong coordinate index, use 0 or 1\")\n" + " }\n" + "}\n"); addFileToFolder(newFolder2, "file.txt", "Something that is not groovy"); addFileToFolder(newFolder2, "Test.foo", "public class Test {}\n"); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of())); }
Set<PublishDiagnosticsParams> diagnostics = compiler.compile(ImmutableSet.of());
assertEquals(NO_ERRORS, compiler.compile(ImmutableSet.of()));