72 lines
1.9 KiB
Java
72 lines
1.9 KiB
Java
package function.builtin;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static testutil.TestUtilities.*;
|
|
|
|
import java.io.*;
|
|
|
|
import org.junit.*;
|
|
|
|
import environment.Environment;
|
|
import function.ArgumentValidator.*;
|
|
import sexpression.*;
|
|
|
|
public class LOADTester {
|
|
|
|
private ByteArrayOutputStream outputStream;
|
|
|
|
private void assertPrinted(String expected) {
|
|
assertEquals(expected, outputStream.toString());
|
|
}
|
|
|
|
private void assertNothingPrinted() {
|
|
assertPrinted("");
|
|
}
|
|
|
|
@Before
|
|
public void setUp() {
|
|
this.outputStream = new ByteArrayOutputStream();
|
|
Environment.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));
|
|
assertPrinted("LOAD: expression begins with ')' - line 1, column 1\n");
|
|
}
|
|
|
|
@Test
|
|
public void loadNonExistentFile_ReturnsNilAndPrintsError() {
|
|
String input = "(load \"doesNotExist.lisp\")";
|
|
|
|
assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
|
|
assertPrinted("LOAD: could not open 'doesNotExist.lisp'\n");
|
|
}
|
|
|
|
@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)");
|
|
}
|
|
|
|
}
|