use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.
the class TestUtils method mockExpression.
public static Expression mockExpression(RedsObject value) {
Expression e = mock(Expression.class);
when(e.execute(any())).thenReturn(value);
return e;
}
use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.
the class IfTest method createIfWithAssignments.
private static If createIfWithAssignments(String variableName, boolean condition, int trueValue, int falseValue) {
Variable var = mockVariable(variableName);
Expression cond = mockExpression(new RedsBoolean(condition));
StatementList thenBody = new StatementList(ImmutableList.of(new Assignment(mockVariable(variableName), mockExpression(trueValue))));
StatementList elseBody = new StatementList(ImmutableList.of(new Assignment(mockVariable(variableName), mockExpression(falseValue))));
return new If(cond, thenBody, elseBody);
}
use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.
the class CallTest method createCall.
private static Call createCall(String name, int... parameters) {
Variable var = mockVariable(name);
List<Expression> params = Arrays.stream(parameters).mapToObj(TestUtils::mockExpression).collect(Collectors.toList());
return new Call(var, params);
}
use of net.taken.redsnake.tree.statements.expressions.Expression in project redsnake by Taken0711.
the class TestUtils method parseStatement.
public static Statement parseStatement(@NotNull String s) {
CharStream inputStream = CharStreams.fromString(s);
RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
ParseTree t = parser.expression();
return (Expression) new ASTBuilder().visit(t);
}
Aggregations