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

45 lines
1.3 KiB
Java
Raw Normal View History

2017-03-10 13:14:16 -05:00
package function.builtin;
import static function.builtin.GENSYM.GENSYM_PREFIX;
2017-11-12 09:42:25 -05:00
import static testutil.TestUtilities.assertSExpressionsDoNotMatch;
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
2017-03-10 13:14:16 -05:00
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)");
}
}