package function.builtin; import static org.junit.Assert.*; import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.*; import sexpression.Nil; public class EVALTester { @Test public void testEval() { String input = "(eval 9)"; assertSExpressionsMatch(evaluateString(input), parseString("9")); } @Test public void testEvalNil() { String input = "(eval ())"; assertSExpressionsMatch(evaluateString(input), parseString("()")); } @Test public void testLookupSymbol() { String symbol = ":symbol"; assertSExpressionsMatch(EVAL.lookupSymbol(symbol), parseString(symbol)); } @Test public void testLookupT() { String symbol = "T"; assertSExpressionsMatch(EVAL.lookupSymbol(symbol), parseString(symbol)); } @Test public void testLookupUndefinedSymbol() { assertNull(EVAL.lookupSymbol("undefined")); } @Test(expected = UndefinedFunctionException.class) public void testEvalUndefinedFunction() { String input = "(funcall 'eval '(undefined))"; evaluateString(input); } @Test(expected = UndefinedSymbolException.class) public void testEvalUndefinedSymbol() { String input = "(eval undefined)"; evaluateString(input); } @Test(expected = DottedArgumentListException.class) public void testEvalWithDottedLambdaList() { String input = "(funcall 'eval (cons '+ 1))"; evaluateString(input); } @Test(expected = TooManyArgumentsException.class) public void testEvalWithTooManyArguments() { evaluateString("(eval '1 '2 '3)"); } @Test(expected = TooFewArgumentsException.class) public void testEvalWithTooFewArguments() { evaluateString("(eval)"); } @Test public void undefinedFunctionException_HasMessageText() { UndefinedFunctionException e = new UndefinedFunctionException(Nil.getInstance()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } @Test public void undefinedSymbolException_HasMessageText() { UndefinedSymbolException e = new UndefinedSymbolException(Nil.getInstance()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } }