2017-01-16 13:38:49 -05:00
|
|
|
package function.builtin;
|
|
|
|
|
2017-03-02 09:54:23 -05:00
|
|
|
import static function.builtin.EVAL.lookupSymbol;
|
2017-01-16 13:38:49 -05:00
|
|
|
import static org.junit.Assert.*;
|
2017-03-02 09:54:23 -05:00
|
|
|
import static sexpression.Nil.NIL;
|
2017-01-16 13:38:49 -05:00
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
import function.builtin.EVAL.*;
|
|
|
|
|
|
|
|
public class EVALTester {
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalNumber() {
|
2017-01-16 13:38:49 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalNil() {
|
2017-01-16 13:38:49 -05:00
|
|
|
String input = "(eval ())";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lookupKeywordSymbol() {
|
2017-01-16 13:38:49 -05:00
|
|
|
String symbol = ":symbol";
|
2017-03-02 09:54:23 -05:00
|
|
|
assertSExpressionsMatch(parseString(symbol), lookupSymbol(symbol));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lookupT() {
|
2017-01-16 13:38:49 -05:00
|
|
|
String symbol = "T";
|
2017-03-02 09:54:23 -05:00
|
|
|
assertSExpressionsMatch(parseString(symbol), lookupSymbol(symbol));
|
2017-01-16 13:38:49 -05:00
|
|
|
}
|
|
|
|
|
2017-02-04 13:51:10 -05:00
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lookupNil() {
|
2017-02-04 13:51:10 -05:00
|
|
|
String symbol = "NIL";
|
2017-03-02 09:54:23 -05:00
|
|
|
assertSExpressionsMatch(parseString(symbol), lookupSymbol(symbol));
|
2017-02-04 13:51:10 -05:00
|
|
|
}
|
|
|
|
|
2017-01-16 13:38:49 -05:00
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lookupUndefinedSymbol() {
|
2017-01-16 13:38:49 -05:00
|
|
|
assertNull(EVAL.lookupSymbol("undefined"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = UndefinedFunctionException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalUndefinedFunction() {
|
2017-01-16 13:38:49 -05:00
|
|
|
String input = "(funcall 'eval '(undefined))";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = UndefinedSymbolException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalUndefinedSymbol() {
|
2017-01-16 13:38:49 -05:00
|
|
|
String input = "(eval undefined)";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = DottedArgumentListException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalWithDottedLambdaList() {
|
2017-01-16 13:38:49 -05:00
|
|
|
String input = "(funcall 'eval (cons '+ 1))";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalWithTooManyArguments() {
|
2017-01-16 13:38:49 -05:00
|
|
|
evaluateString("(eval '1 '2 '3)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void evalWithTooFewArguments() {
|
2017-01-16 13:38:49 -05:00
|
|
|
evaluateString("(eval)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void undefinedFunctionException_HasMessageText() {
|
2017-03-02 09:54:23 -05:00
|
|
|
UndefinedFunctionException e = new UndefinedFunctionException(NIL);
|
2017-01-16 13:38:49 -05:00
|
|
|
|
|
|
|
assertNotNull(e.getMessage());
|
|
|
|
assertTrue(e.getMessage().length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void undefinedSymbolException_HasMessageText() {
|
2017-03-02 09:54:23 -05:00
|
|
|
UndefinedSymbolException e = new UndefinedSymbolException(NIL);
|
2017-01-16 13:38:49 -05:00
|
|
|
|
|
|
|
assertNotNull(e.getMessage());
|
|
|
|
assertTrue(e.getMessage().length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|