1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package org.javacs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.nio.file.Paths;
import java.util.Collections;
import org.junit.Test;
public class ParserTest {
@Test
public void testMatchesTitleCase() {
assertTrue(Parser.matchesTitleCase("FooBar", "fb"));
assertTrue(Parser.matchesTitleCase("FooBar", "fob"));
assertTrue(Parser.matchesTitleCase("AnyPrefixFooBar", "fb"));
assertTrue(Parser.matchesTitleCase("AutocompleteBetweenLines", "ABetweenLines"));
assertTrue(Parser.matchesTitleCase("UPPERFooBar", "fb"));
assertFalse(Parser.matchesTitleCase("Foobar", "fb"));
assertTrue(Parser.matchesTitleCase("Prefix FooBar", "fb"));
assertTrue(Parser.matchesTitleCase("Prefix FooBar", "fob"));
assertTrue(Parser.matchesTitleCase("Prefix AnyPrefixFooBar", "fb"));
assertTrue(Parser.matchesTitleCase("Prefix AutocompleteBetweenLines", "ABetweenLines"));
assertTrue(Parser.matchesTitleCase("Prefix UPPERFooBar", "fb"));
assertFalse(Parser.matchesTitleCase("Foo Bar", "fb"));
}
@Test
public void searchLargeFile() {
var largeFile = Paths.get(FindResource.uri("/org/javacs/example/LargeFile.java"));
assertTrue(Parser.containsWordMatching(largeFile, "removeMethodBodies"));
assertFalse(Parser.containsWordMatching(largeFile, "removeMethodBodiez"));
}
@Test
public void searchSmallFile() {
var smallFile = Paths.get(FindResource.uri("/org/javacs/example/Goto.java"));
assertTrue(Parser.containsWordMatching(smallFile, "nonDefaultConstructor"));
assertFalse(Parser.containsWordMatching(smallFile, "removeMethodBodies"));
}
@Test
public void largeFilePossibleReference() {
var largeFile = Paths.get(FindResource.uri("/org/javacs/example/LargeFile.java"));
assertTrue(JavaCompilerService.containsImport("java.util.logging", "Logger", largeFile));
assertTrue(JavaCompilerService.containsWord("removeMethodBodies", largeFile));
assertFalse(JavaCompilerService.containsWord("removeMethodBodiez", largeFile));
}
@Test
public void findAutocompleteBetweenLines() {
var rel = Paths.get("src", "org", "javacs", "example", "AutocompleteBetweenLines.java");
var file = LanguageServerFixture.DEFAULT_WORKSPACE_ROOT.resolve(rel);
assertTrue(Parser.containsWordMatching(file, "ABetweenLines"));
}
@Test
public void findExistingImports() {
var rel = Paths.get("src", "org", "javacs", "doimport");
var dir = LanguageServerFixture.DEFAULT_WORKSPACE_ROOT.resolve(rel);
var sourcePath = new SourcePath(Collections.singleton(dir));
var existing = Parser.existingImports(sourcePath.allJavaFiles());
assertThat(existing.classes, hasItems("java.util.List"));
assertThat(existing.packages, hasItems("java.util", "java.io"));
}
}
|