2016-12-22 10:32:48 -05:00
|
|
|
package testutil;
|
2016-12-16 11:26:53 -05:00
|
|
|
|
2017-11-23 11:35:28 -05:00
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
import static org.junit.Assert.assertThat;
|
2017-03-02 09:54:23 -05:00
|
|
|
import static sexpression.Nil.NIL;
|
|
|
|
import static sexpression.Symbol.T;
|
2016-12-16 11:26:53 -05:00
|
|
|
|
2017-03-02 09:54:23 -05:00
|
|
|
import sexpression.SExpression;
|
2016-12-16 11:26:53 -05:00
|
|
|
|
2017-01-27 11:37:11 -05:00
|
|
|
public final class TypeAssertions {
|
2016-12-16 11:26:53 -05:00
|
|
|
|
|
|
|
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));
|
2016-12-16 11:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void assertNil(SExpression sExpression) {
|
2017-11-23 11:35:28 -05:00
|
|
|
assertThat(sExpression, is(NIL));
|
2016-12-16 11:26:53 -05:00
|
|
|
|
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));
|
2016-12-16 11:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-12-16 11:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-12-16 11:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2016-12-16 11:26:53 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-16 11:26:53 -05:00
|
|
|
}
|