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

67 lines
1.7 KiB
Java
Raw Normal View History

package function.builtin.cons;
2017-11-12 09:42:25 -05:00
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
import static testutil.TestUtilities.parseString;
import org.junit.Test;
2017-11-12 09:42:25 -05:00
import function.ArgumentValidator.TooFewArgumentsException;
import function.ArgumentValidator.TooManyArgumentsException;
import sexpression.Cons;
import sexpression.Symbol;
import testutil.SymbolAndFunctionCleaner;
public class CONSTest extends SymbolAndFunctionCleaner {
@Test
public void consWithNilValues() {
String input = "(cons () nil)";
assertSExpressionsMatch(parseString("(())"), evaluateString(input));
}
@Test
public void consWithTwoSymbols() {
String input = "(cons 'a 'b)";
assertSExpressionsMatch(new Cons(new Symbol("A"), new Symbol("B")), evaluateString(input));
}
@Test
public void consWithListAsRest() {
String input = "(cons 1 '(2 3))";
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
}
2017-02-06 13:43:27 -05:00
@Test
public void consWithTwoLists() {
String input = "(cons '(1 2) '(3 4))";
assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input));
}
@Test
public void consWithList() {
String input = "(cons nil '(2 3))";
assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input));
}
@Test(expected = TooManyArgumentsException.class)
public void consWithTooManyArguments() {
String input = "(cons 1 2 3)";
evaluateString(input);
}
@Test(expected = TooFewArgumentsException.class)
public void consWithTooFewArguments() {
String input = "(cons 1)";
evaluateString(input);
}
}