use of net.taken.redsnake.tree.statements.If 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.If in project redsnake by Taken0711.
the class IfTest method shouldNotExecuteElseBlockWhenExecutingIfWithFalseAndElseClause.
@Test
void shouldNotExecuteElseBlockWhenExecutingIfWithFalseAndElseClause() {
If anIf = createIfWithAssignments("a", false, 1, 2);
env.putVariable("a", new RedsInteger(0));
anIf.execute(env);
assertEquals(new RedsInteger(2), env.getVariable("a"));
}
use of net.taken.redsnake.tree.statements.If in project redsnake by Taken0711.
the class IfTest method shouldNotExecuteThenBlockWhenExecutingIfWithFalseAndNoElseClause.
@Test
void shouldNotExecuteThenBlockWhenExecutingIfWithFalseAndNoElseClause() {
If anIf = createIfWithAssignments("a", false, 1);
env.putVariable("a", new RedsInteger(0));
anIf.execute(env);
assertEquals(new RedsInteger(0), env.getVariable("a"));
}
use of net.taken.redsnake.tree.statements.If in project redsnake by Taken0711.
the class IfTest method shouldExecuteTheGoodBlockWhenExecutingIfWithTrueAndElseClause.
@Test
void shouldExecuteTheGoodBlockWhenExecutingIfWithTrueAndElseClause() {
If anIf = createIfWithAssignments("a", true, 1, 2);
env.putVariable("a", new RedsInteger(0));
anIf.execute(env);
assertEquals(new RedsInteger(1), env.getVariable("a"));
}
Aggregations