2017-01-26 15:58:15 -05:00
|
|
|
package function.builtin;
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
import static org.junit.Assert.*;
|
2017-01-26 15:58:15 -05:00
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
2017-02-06 13:39:05 -05:00
|
|
|
import environment.RuntimeEnvironment;
|
2017-01-26 15:58:15 -05:00
|
|
|
import function.ArgumentValidator.*;
|
2017-01-27 10:51:25 -05:00
|
|
|
import sexpression.*;
|
2017-01-26 15:58:15 -05:00
|
|
|
|
|
|
|
public class LOADTester {
|
|
|
|
|
|
|
|
private ByteArrayOutputStream outputStream;
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
private void assertSomethingPrinted() {
|
|
|
|
assertTrue(outputStream.toByteArray().length > 0);
|
2017-01-26 15:58:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertNothingPrinted() {
|
2017-02-09 11:00:23 -05:00
|
|
|
assertTrue(outputStream.toByteArray().length == 0);
|
2017-01-26 15:58:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
this.outputStream = new ByteArrayOutputStream();
|
2017-02-06 13:39:05 -05:00
|
|
|
RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(outputStream));
|
2017-01-26 15:58:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void loadGoodFile_ReturnsTAndPrintsNothing() {
|
|
|
|
String input = "(load \"test/function/builtin/test-files/load-good.lisp\")";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(Symbol.T, evaluateString(input));
|
2017-01-26 15:58:15 -05:00
|
|
|
assertNothingPrinted();
|
|
|
|
}
|
2017-01-26 16:00:47 -05:00
|
|
|
|
2017-01-26 15:58:15 -05:00
|
|
|
@Test
|
|
|
|
public void loadBadFile_ReturnsNilAndPrintsError() {
|
|
|
|
String input = "(load \"test/function/builtin/test-files/load-bad.lisp\")";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
|
2017-02-09 11:00:23 -05:00
|
|
|
assertSomethingPrinted();
|
2017-01-26 15:58:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void loadNonExistentFile_ReturnsNilAndPrintsError() {
|
|
|
|
String input = "(load \"doesNotExist.lisp\")";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
|
2017-02-09 11:00:23 -05:00
|
|
|
assertSomethingPrinted();
|
2017-01-26 15:58:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@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)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|