package function.builtin.cons; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; import org.junit.Test; 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)); } @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() { evaluateString("(cons 1 2 3)"); } @Test(expected = TooFewArgumentsException.class) public void consWithTooFewArguments() { evaluateString("(cons 1)"); } }