AlluxioInterpreter extends Interpreter { @Override public List<InterpreterCompletion> completion(String buf, int cursor, InterpreterContext interpreterContext) { String[] words = splitAndRemoveEmpty(splitAndRemoveEmpty(buf, "\n"), " "); String lastWord = ""; if (words.length > 0) { lastWord = words[ words.length - 1 ]; } List<InterpreterCompletion> voices = new LinkedList<>(); for (String command : keywords) { if (command.startsWith(lastWord)) { voices.add(new InterpreterCompletion(command, command, CompletionType.command.name())); } } 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,
      InterpreterContext interpreterContext);  }
@Test public void testCompletion() { List expectedResultOne = Arrays.asList( new InterpreterCompletion("cat", "cat", CompletionType.command.name()), new InterpreterCompletion("chgrp", "chgrp", CompletionType.command.name()), new InterpreterCompletion("chmod", "chmod", CompletionType.command.name()), new InterpreterCompletion("chown", "chown", CompletionType.command.name()), new InterpreterCompletion("copyFromLocal", "copyFromLocal", CompletionType.command.name()), new InterpreterCompletion("copyToLocal", "copyToLocal", CompletionType.command.name()), new InterpreterCompletion("count", "count", CompletionType.command.name()), new InterpreterCompletion("createLineage", "createLineage", CompletionType.command.name())); List expectedResultTwo = Arrays.asList( new InterpreterCompletion("copyFromLocal", "copyFromLocal", CompletionType.command.name()), new InterpreterCompletion("copyToLocal", "copyToLocal", CompletionType.command.name()), new InterpreterCompletion("count", "count", CompletionType.command.name())); List expectedResultThree = Arrays.asList( new InterpreterCompletion("copyFromLocal", "copyFromLocal", CompletionType.command.name()), new InterpreterCompletion("copyToLocal", "copyToLocal", CompletionType.command.name())); List expectedResultNone = new ArrayList<>(); List<InterpreterCompletion> resultOne = alluxioInterpreter.completion("c", 0, null); List<InterpreterCompletion> resultTwo = alluxioInterpreter.completion("co", 0, null); List<InterpreterCompletion> resultThree = alluxioInterpreter.completion("copy", 0, null); List<InterpreterCompletion> resultNotMatch = alluxioInterpreter.completion("notMatch", 0, null); List<InterpreterCompletion> resultAll = alluxioInterpreter.completion("", 0, null); Assert.assertEquals(expectedResultOne, resultOne); Assert.assertEquals(expectedResultTwo, resultTwo); Assert.assertEquals(expectedResultThree, resultThree); Assert.assertEquals(expectedResultNone, resultNotMatch); List allCompletionList = new ArrayList<>(); for (InterpreterCompletion ic : resultAll) { allCompletionList.add(ic.getName()); } Assert.assertEquals(alluxioInterpreter.keywords, allCompletionList); }