@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())); }
@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())); }
File newFolder1 = root.newFolder(); File newFolder2 = root.newFolder(); addFileToFolder(newFolder1, "test1.groovy", "class Coordinates {\n" + " double latitude\n" + " }\n" + "}\n"); addFileToFolder(newFolder2, "test2.groovy", "class Coordinates2 {\n" + " double latitude\n" + " }\n" + "}\n"); addFileToFolder(newFolder2, "test3.groovy", "class Coordinates3 {\n" + " double latitude\n" + " }\n" + "}\n"); addFileToFolder(root.getRoot(), "test4.groovy", "class ExceptionNew {}");
@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 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_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 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()); }
File newFolder1 = root.newFolder(); File newFolder2 = root.newFolder(); File test1 = addFileToFolder(newFolder1, "test1.groovy", "class Coordinates {\n" + " double latitude\n" + " }\n" + "}\n"); File test2 = addFileToFolder(newFolder2, "test2.groovy", "class Coordinates2 {\n" + " double latitude\n" + " }\n" + "}\n"); addFileToFolder(newFolder2, "test3.groovy", "class Coordinates3 {\n" + " double latitude\n" + " }\n" + "}\n"); addFileToFolder(root.getRoot(), "test4.groovy", "class ExceptionNew {}\n");
@Test public void testHandleFileClosed() throws IOException { File newFolder1 = root.newFolder(); File catFile = addFileToFolder(newFolder1, "Cat.groovy", "class Cat {\n" + "}\n");
@Test public void testHandleChangeWatchedFiles_changed() throws IOException { File newFolder1 = root.newFolder(); File catFile = addFileToFolder(newFolder1, "Cat.groovy", "class Cat {\n" + "}\n");
@Test public void testHandleFileChanged() throws IOException { File newFolder1 = root.newFolder(); File catFile = addFileToFolder(newFolder1, "Cat.groovy", "class Cat {\n" + "}\n");
@Test public void testHandleFileSaved() throws IOException { File newFolder1 = root.newFolder(); File catFile = addFileToFolder(newFolder1, "Cat.groovy", "class Cat {\n" + "}\n");