StellarShell extends AeshConsoleCallback implements Completion { @Override public int execute(ConsoleOperation output) throws InterruptedException { String expression = StringUtils.trimToEmpty(output.getBuffer()); if(StringUtils.isNotBlank(expression) ) { StellarResult result = executor.execute(expression); if(result.isSuccess()) { result.getValue().ifPresent(v -> writeLine(v.toString())); } else if (result.isError()) { result.getException().ifPresent(e -> writeLine(ERROR_PROMPT + e.getMessage())); result.getException().ifPresent(e -> e.printStackTrace()); } else if(result.isTerminate()) { handleQuit(); } else { throw new IllegalStateException("An execution result is neither a success nor a failure. Please file a bug report."); } } return 0; } StellarShell(String[] args); static void main(String[] args); void run(); @Override int execute(ConsoleOperation output); @Override void complete(CompleteOperation completeOperation); StellarShellExecutor getExecutor(); Console getConsole(); static final String ERROR_PROMPT; static final String STELLAR_PROPERTIES_FILENAME; }
@Test public void testExecuteStellar() throws Exception { stellarShell.execute(createOp("2 + 2")); assertEquals("4", stdout()); }
@Test public void testBackslashInStrings() throws Exception { stellarShell.execute(createOp("SPLIT('foo\\\\bar', '\\\\')")); assertEquals("[foo, bar]", stdout()); }
@Test public void testExecuteWithStellarList() throws Exception { stellarShell.execute(createOp("[1,2,3,4,5]")); assertEquals("[1, 2, 3, 4, 5]", stdout()); }
@Test public void testExecuteWithStellarMap() throws Exception { stellarShell.execute(createOp("{ 'foo':2, 'key':'val' }")); assertEquals("{foo=2, key=val}", stdout()); }
@Test public void testExecuteBadStellar() throws Exception { stellarShell.execute(createOp("2 + ")); final String expected = "[!] Unable to parse: 2 + "; assertTrue(stdout().startsWith(expected)); }
@Test public void testExecuteNoop() throws Exception { stellarShell.execute(createOp("x")); assertEquals("", stdout()); }