2017-01-16 13:38:49 -05:00
|
|
|
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)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("9"), evaluateString(input));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testEvalNil() {
|
|
|
|
String input = "(eval ())";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLookupSymbol() {
|
|
|
|
String symbol = ":symbol";
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLookupT() {
|
|
|
|
String symbol = "T";
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
2017-02-04 13:51:10 -05:00
|
|
|
@Test
|
|
|
|
public void testLookupNil() {
|
|
|
|
String symbol = "NIL";
|
|
|
|
assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
|
|
|
|
}
|
|
|
|
|
2017-01-16 13:38:49 -05:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|