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

81 lines
1.6 KiB
Java
Raw Normal View History

package function.builtin.special;
import static testutil.TestUtilities.*;
import static testutil.TypeAssertions.*;
import org.junit.*;
import function.builtin.EVAL.UndefinedSymbolException;
import sexpression.LispNumber;
import table.ExecutionContext;
2017-03-15 13:37:39 -04:00
public class ORTest {
private ExecutionContext executionContext;
2017-03-15 13:37:39 -04:00
public ORTest() {
this.executionContext = ExecutionContext.getInstance();
}
@Before
public void setUp() {
executionContext.clearContext();
}
@After
public void tearDown() {
executionContext.clearContext();
}
@Test
public void orByItself() {
String input = "(or)";
assertNil(evaluateString(input));
}
@Test
public void orWithNil() {
String input = "(or nil)";
assertNil(evaluateString(input));
}
@Test
public void orWithT() {
String input = "(or t)";
assertT(evaluateString(input));
}
@Test
public void orWithNumber() {
String input = "(or 7)";
assertSExpressionsMatch(new LispNumber("7"), evaluateString(input));
}
@Test
public void orWithSeveralValues() {
String input = "(or nil nil nil t nil)";
assertT(evaluateString(input));
}
@Test
public void orWithSeveralNumbers() {
String input = "(or 1 2 3)";
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
}
@Test(expected = UndefinedSymbolException.class)
public void orShortCircuits() {
2017-03-07 16:41:26 -05:00
String input = "(or t (setq x 22))";
assertT(evaluateString(input));
evaluateString("x");
}
}