struct Expr b = SYMBOL(gc, "b");
struct Expr c = SYMBOL(gc, "c");
- struct Expr a_pair = CONS(gc, a, NUMBER(gc, 10.0f));
- struct Expr b_pair = CONS(gc, b, NUMBER(gc, 20.0f));
- struct Expr c_pair = CONS(gc, c, NUMBER(gc, 30.0f));
+ struct Expr a_pair = CONS(gc, a, NUMBER(gc, 10));
+ struct Expr b_pair = CONS(gc, b, NUMBER(gc, 20));
+ struct Expr c_pair = CONS(gc, c, NUMBER(gc, 30));
struct Expr alist =
CONS(gc, a_pair,
Gc *gc = create_gc();
struct Expr input = list(
- gc, 4,
- NUMBER(gc, 42),
- STRING(gc, "hello"),
- SYMBOL(gc, "world"),
+ gc, "dsqe",
+ 42,
+ "hello",
+ "world",
CONS(gc, NUMBER(gc, 1), NUMBER(gc, 2)));
long int d = 0;
{
Gc *gc = create_gc();
- struct Expr input = list(
- gc, 4,
- NUMBER(gc, 1),
- NUMBER(gc, 2),
- NUMBER(gc, 3),
- NUMBER(gc, 4));
+ struct Expr input = list(gc, "dddd", 1, 2, 3, 4);
long int x = 0;
struct Expr xs = NIL(gc);
fprintf(stderr, "Expected: 1, Actual: %ld\n", x);
});
- ASSERT_TRUE(equal(xs, list(gc, 3, NUMBER(gc, 2), NUMBER(gc, 3), NUMBER(gc, 4))), {
+ ASSERT_TRUE(equal(xs, list(gc, "ddd", 2, 3, 4)), {
fprintf(stderr, "Expected: (2 3 4), Actual: ");
print_expr_as_sexpr(stderr, xs);
fprintf(stderr, "\n");
Gc *gc = create_gc();
struct Expr input = list(
- gc, 4,
- NUMBER(gc, 1),
- NUMBER(gc, 2),
- NUMBER(gc, 3),
- NUMBER(gc, 4));
+ gc, "dddd", 1, 2, 3, 4);
long int x = 0, y = 0;
struct EvalResult result = match_list(gc, "dddd", input, &x, NULL, &y, NULL);
return 0;
}
+TEST(match_list_singleton_tail_test)
+{
+ Gc *gc = create_gc();
+
+ struct Expr input = list(gc, "d", 1);
+ long int x;
+ struct Expr xs = NIL(gc);
+ struct EvalResult res = match_list(gc, "d*", input, &x, &xs);
+
+ ASSERT_TRUE(!res.is_error, {
+ fprintf(stderr, "Matching failed: ");
+ print_expr_as_sexpr(stderr, res.expr);
+ fprintf(stderr, "\n");
+ });
+
+ ASSERT_LONGINTEQ(1L, x);
+ ASSERT_TRUE(nil_p(xs), {
+ fprintf(stderr, "Tail doesn't appear to be NIL: ");
+ print_expr_as_sexpr(stderr, xs);
+ fprintf(stderr, "\n");
+ });
+
+ destroy_gc(gc);
+
+ return 0;
+}
+
TEST_SUITE(interpreter_suite)
{
TEST_RUN(equal_test);
TEST_RUN(match_list_empty_list_test);
TEST_RUN(match_list_head_tail_test);
TEST_RUN(match_list_wildcard_test);
+ TEST_RUN(match_list_singleton_tail_test);
return 0;
}