AlluxioInterpreter extends Interpreter { @Override public List<InterpreterCompletion> completion(String buf, int cursor) { String[] words = splitAndRemoveEmpty(splitAndRemoveEmpty(buf, "\n"), " "); String lastWord = ""; if (words.length > 0) { lastWord = words[ words.length - 1 ]; } ArrayList voices = new ArrayList<>(); for (String command : keywords) { if (command.startsWith(lastWord)) { voices.add(command); } } return voices; } AlluxioInterpreter(Properties property); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String st, InterpreterContext context); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override List<InterpreterCompletion> completion(String buf, int cursor);  }
@Test public void testCompletion() { List expectedResultOne = Arrays.asList("cat", "chgrp", "chmod", "chown", "copyFromLocal", "copyToLocal", "count", "createLineage"); List expectedResultTwo = Arrays.asList("copyFromLocal", "copyToLocal", "count"); List expectedResultThree = Arrays.asList("copyFromLocal", "copyToLocal"); List expectedResultNone = new ArrayList<String>(); List<InterpreterCompletion> resultOne = alluxioInterpreter.completion("c", 0); List<InterpreterCompletion> resultTwo = alluxioInterpreter.completion("co", 0); List<InterpreterCompletion> resultThree = alluxioInterpreter.completion("copy", 0); List<InterpreterCompletion> resultNotMatch = alluxioInterpreter.completion("notMatch", 0); List<InterpreterCompletion> resultAll = alluxioInterpreter.completion("", 0); Assert.assertEquals(expectedResultOne, resultOne); Assert.assertEquals(expectedResultTwo, resultTwo); Assert.assertEquals(expectedResultThree, resultThree); Assert.assertEquals(expectedResultNone, resultNotMatch); Assert.assertEquals(alluxioInterpreter.keywords, resultAll); }