transcendental-lisp/test/function/builtin/GENSYMTest.java

43 lines
1.2 KiB
Java
Raw Normal View History

2017-03-10 13:14:16 -05:00
package function.builtin;
import static function.builtin.GENSYM.GENSYM_PREFIX;
import static testutil.TestUtilities.*;
import static testutil.TypeAssertions.assertSymbol;
import org.junit.Test;
import function.ArgumentValidator.TooManyArgumentsException;
import testutil.SymbolAndFunctionCleaner;
2017-03-10 13:14:16 -05:00
import token.TokenFactory.BadCharacterException;
public class GENSYMTest extends SymbolAndFunctionCleaner {
2017-03-10 13:14:16 -05:00
@Test
public void gensymCreatesSymbol() {
assertSymbol(evaluateString("(gensym)"));
}
@Test
public void gensymCreatesUniqueSymbol() {
assertSExpressionsDoNotMatch(evaluateString("(gensym)"), evaluateString("(gensym)"));
}
@Test
public void simpleGensymUsage() {
String input = "(let ((x (gensym))) (set x 23) (eval x))";
assertSExpressionsMatch(evaluateString("23"), evaluateString(input));
}
@Test(expected = BadCharacterException.class)
public void cannotUseGensymValueManually() {
String variableName = GENSYM_PREFIX + 1;
evaluateString("(setq " + variableName + " 100)");
}
@Test(expected = TooManyArgumentsException.class)
public void gensymWithTooManyArguments() {
evaluateString("(gensym 1)");
}
}