transcendental-lisp/test/function/builtin/special/IFTester.java

92 lines
2.1 KiB
Java

package function.builtin.special;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.*;
import function.ArgumentValidator.*;
import function.builtin.EVAL.UndefinedSymbolException;
import table.ExecutionContext;
public class IFTester {
private ExecutionContext executionContext;
public IFTester() {
this.executionContext = ExecutionContext.getInstance();
}
@Before
public void setUp() {
executionContext.clearContext();
}
@After
public void tearDown() {
executionContext.clearContext();
}
@Test
public void ifWithOneExpression_ReturnsExpression() {
String input = "(if t t)";
assertT(evaluateString(input));
}
@Test
public void ifWithOneExpression_ReturnsNil() {
String input = "(if nil t)";
assertNil(evaluateString(input));
}
@Test
public void ifWithTwoExpressions_ReturnsFirst() {
String input = "(if t t nil)";
assertT(evaluateString(input));
}
@Test
public void ifWithTwoExpressions_ReturnsSecond() {
String input = "(if nil nil t)";
assertT(evaluateString(input));
}
@Test
public void ifWithNumericConditional() {
String input = "(if 23 t nil)";
assertT(evaluateString(input));
}
@Test(expected = UndefinedSymbolException.class)
public void ifWithNilCondition_DoesNotEvaluateThenForm() {
String input = "(if nil (setq x 22))";
assertNil(evaluateString(input));
evaluateString("x");
}
@Test(expected = UndefinedSymbolException.class)
public void ifWithTrueCondition_DoesNotEvaluateElseForm() {
String input = "(if t nil (setq x 22))";
assertNil(evaluateString(input));
evaluateString("x");
}
@Test(expected = TooFewArgumentsException.class)
public void ifWithTooFewArguments() {
evaluateString("(if t)");
}
@Test(expected = TooManyArgumentsException.class)
public void ifWithTooManyArguments() {
evaluateString("(if t t t t)");
}
}