transcendental-lisp/test/function/builtin/cons/RESTTest.java

55 lines
1.2 KiB
Java
Raw Normal View History

package function.builtin.cons;
import static testutil.TestUtilities.*;
import org.junit.Test;
import function.ArgumentValidator.*;
2017-03-15 13:37:39 -04:00
public class RESTTest {
@Test
public void restOfNil() {
String input = "(rest nil)";
assertSExpressionsMatch(parseString("()"), evaluateString(input));
}
@Test
public void restOfList() {
String input = "(rest '(1 2 3))";
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
}
@Test
public void cdrOfList() {
String input = "(cdr '(1 2 3))";
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
}
@Test
public void nestedRestOfList() {
String input = "(rest (rest '(1 2 3)))";
assertSExpressionsMatch(parseString("(3)"), evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)
public void restOfSymbol() {
evaluateString("(rest 'x)");
}
@Test(expected = TooManyArgumentsException.class)
public void restWithTooManyArguments() {
evaluateString("(rest '(1 2) '(1 2) \"oh\")");
}
@Test(expected = TooFewArgumentsException.class)
public void restWithTooFewArguments() {
evaluateString("(rest)");
}
}