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

72 lines
1.9 KiB
Java

package function.builtin;
import static org.junit.Assert.*;
import static testutil.TestUtilities.*;
import java.io.*;
import org.junit.*;
import environment.RuntimeEnvironment;
import function.ArgumentValidator.*;
import sexpression.*;
public class LOADTester {
private ByteArrayOutputStream outputStream;
private void assertSomethingPrinted() {
assertTrue(outputStream.toByteArray().length > 0);
}
private void assertNothingPrinted() {
assertTrue(outputStream.toByteArray().length == 0);
}
@Before
public void setUp() {
this.outputStream = new ByteArrayOutputStream();
RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(outputStream));
}
@Test
public void loadGoodFile_ReturnsTAndPrintsNothing() {
String input = "(load \"test/function/builtin/test-files/load-good.lisp\")";
assertSExpressionsMatch(Symbol.T, evaluateString(input));
assertNothingPrinted();
}
@Test
public void loadBadFile_ReturnsNilAndPrintsError() {
String input = "(load \"test/function/builtin/test-files/load-bad.lisp\")";
assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
assertSomethingPrinted();
}
@Test
public void loadNonExistentFile_ReturnsNilAndPrintsError() {
String input = "(load \"doesNotExist.lisp\")";
assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
assertSomethingPrinted();
}
@Test(expected = BadArgumentTypeException.class)
public void testLoadWithBadArgumentType() {
evaluateString("(load '1)");
}
@Test(expected = TooManyArgumentsException.class)
public void testLoadWithTooManyArguments() {
evaluateString("(load \"1\" \"2\")");
}
@Test(expected = TooFewArgumentsException.class)
public void testLoadWithTooFewArguments() {
evaluateString("(load)");
}
}