transcendental-lisp/test/sexpression/SExpressionTester.java

71 lines
1.7 KiB
Java
Raw Normal View History

package sexpression;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
public class SExpressionTester {
private void assertSExpressionMatchesString(String expected, SExpression sExpression) {
assertEquals(expected, sExpression.toString());
}
@Before
public void setUp() throws Exception {}
@Test
public void testNilToString() {
String input = "NIL";
assertSExpressionMatchesString(input, Nil.getUniqueInstance());
}
@Test
public void testNumberToString() {
String input = "12";
assertSExpressionMatchesString(input, new LispNumber(input));
}
@Test
public void testNumberValueToString() {
String expected = "12";
assertSExpressionMatchesString(expected, new LispNumber(12));
}
@Test
public void testStringToString() {
String input = "\"hi\"";
assertSExpressionMatchesString(input, new LispString(input));
}
@Test
public void testSymbolToString() {
String input = "symbol";
assertSExpressionMatchesString(input.toUpperCase(), new Symbol(input));
}
@Test
public void testSimpleConsToString() {
String expected = "(1)";
Cons cons = new Cons(new LispNumber(1), Nil.getUniqueInstance());
assertSExpressionMatchesString(expected, cons);
}
@Test
public void testComplexConsToString() {
String expected = "(1 A \"string\")";
Cons list = new Cons(new LispNumber(1),
new Cons(new Symbol("a"),
new Cons(new LispString("\"string\""), Nil.getUniqueInstance())));
assertSExpressionMatchesString(expected, list);
}
}