Skip to content

Commit 5147970

Browse files
committed
ScriptEngineTest: test the AutoCompleter logic
1 parent cbe7097 commit 5147970

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/java/org/scijava/script/ScriptEngineTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,35 @@ public void testScriptModuleValue() throws Exception {
9797
assertEquals(context, info.context());
9898
}
9999

100+
@Test
101+
public void testAutoCompleter() {
102+
final ScriptLanguage hello = scriptService.getLanguageByName("Hello");
103+
final ScriptEngine engine = hello.getScriptEngine();
104+
final AutoCompleter ac = hello.getAutoCompleter();
105+
106+
// test all matches
107+
engine.put("thing", new Object());
108+
final AutoCompletionResult result = ac.autocomplete("thing.", engine);
109+
assertEquals(0, result.getStartIndex());
110+
final List<String> matches = result.getMatches();
111+
final List<String> expected = Arrays.asList("thing.equals(",
112+
"thing.getClass(", "thing.hashCode(", "thing.notify(", "thing.notifyAll(",
113+
"thing.toString(", "thing.wait(");
114+
assertEquals(matches, expected);
115+
116+
// test prefix
117+
engine.put("hello", "world");
118+
final AutoCompletionResult cWords = ac.autocomplete("hello.c", engine);
119+
assertEquals(0, cWords.getStartIndex());
120+
final List<String> cMatches = cWords.getMatches();
121+
final List<String> cExpected = Arrays.asList("hello.CASE_INSENSITIVE_ORDER",
122+
"hello.charAt(", "hello.chars(", "hello.codePointAt(",
123+
"hello.codePointBefore(", "hello.codePointCount(", "hello.codePoints(",
124+
"hello.compareTo(", "hello.compareToIgnoreCase(", "hello.concat(",
125+
"hello.contains(", "hello.contentEquals(", "hello.copyValueOf(");
126+
assertEquals(cMatches, cExpected);
127+
}
128+
100129
@Plugin(type = ScriptLanguage.class)
101130
public static class Rot13 extends AbstractScriptLanguage {
102131

0 commit comments

Comments
 (0)