use of org.apache.metron.stellar.common.shell.VariableResult in project metron by apache.
the class StellarInterpreterTest method testExecuteStellarMultipleLines.
/**
* Ensure that we can run Stellar code in the interpreter.
*/
@Test
public void testExecuteStellarMultipleLines() {
// multi-line input
String input = "x := 2 + 2" + System.lineSeparator() + "y := 4 + 4";
InterpreterResult result = interpreter.interpret(input, context);
// expect x == 4 and y == 8
Map<String, VariableResult> vars = interpreter.getExecutor().getState();
assertEquals(4, vars.get("x").getResult());
assertEquals(8, vars.get("y").getResult());
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// the output is the result of only the 'last' expression
InterpreterResultMessage message = result.message().get(0);
assertEquals("8", message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.metron.stellar.common.shell.VariableResult in project metron by apache.
the class ShellFunctionsTest method testListVarsWithVars.
@Test
public void testListVarsWithVars() {
Map<String, VariableResult> variables = ImmutableMap.of("foo", VariableResult.withExpression(2.0, "1 + 1"));
Context context = new Context.Builder().with(Context.Capabilities.SHELL_VARIABLES, () -> variables).build();
Object out = run("SHELL_LIST_VARS()", new HashMap<>(), context);
assertEquals(expectedListWithFoo, out);
}
Aggregations