transcendental-lisp/test/testutil/TypeAssertions.java

131 lines
5.6 KiB
Java
Raw Normal View History

package testutil;
2017-11-23 11:35:28 -05:00
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import sexpression.SExpression;
2017-01-27 11:37:11 -05:00
public final class TypeAssertions {
public static void assertList(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(false));
assertThat(sExpression.isCons(), is(true));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(true));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(false));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(false));
}
public static void assertNil(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression, is(NIL));
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(true));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(true));
assertThat(sExpression.isNull(), is(true));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(true));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(false));
}
public static void assertNumber(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(true));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(false));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(true));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(false));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(false));
}
public static void assertString(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(true));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(false));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(true));
assertThat(sExpression.isSymbol(), is(false));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(false));
}
public static void assertSymbol(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(true));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(false));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(true));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(false));
}
2017-01-27 11:37:11 -05:00
public static void assertT(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression, is(T));
2017-01-27 11:37:11 -05:00
}
2017-03-11 15:41:07 -05:00
public static void assertBackTickExpression(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(false));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(false));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(false));
assertThat(sExpression.isBackquote(), is(true));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(false));
2017-03-11 15:41:07 -05:00
}
public static void assertCommaExpression(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(false));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(false));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(false));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(true));
assertThat(sExpression.isAtSign(), is(false));
2017-03-11 15:41:07 -05:00
}
public static void assertAtSignExpression(SExpression sExpression) {
2017-11-23 11:35:28 -05:00
assertThat(sExpression.isAtom(), is(false));
assertThat(sExpression.isCons(), is(false));
assertThat(sExpression.isFunction(), is(false));
assertThat(sExpression.isList(), is(false));
assertThat(sExpression.isNull(), is(false));
assertThat(sExpression.isNumber(), is(false));
assertThat(sExpression.isString(), is(false));
assertThat(sExpression.isSymbol(), is(false));
assertThat(sExpression.isBackquote(), is(false));
assertThat(sExpression.isComma(), is(false));
assertThat(sExpression.isAtSign(), is(true));
2017-03-11 15:41:07 -05:00
}
}