Improve tests
This commit is contained in:
parent
c728f020e2
commit
1f59a5bb0e
198
src/main-test.c
198
src/main-test.c
|
@ -5,9 +5,12 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct Object *result = NULL;
|
||||
|
||||
// Syntax
|
||||
static void test_begin();
|
||||
static void test_if();
|
||||
static void test_quote();
|
||||
// Arcane Scheme Lisp internals
|
||||
static void test_arcane_SLASH_tokenize();
|
||||
static void test_arcane_SLASH_typeof();
|
||||
|
@ -40,6 +43,7 @@ int main()
|
|||
// Syntax
|
||||
test_begin();
|
||||
test_if();
|
||||
test_quote();
|
||||
// Arcane Scheme Lisp internals
|
||||
test_arcane_SLASH_tokenize();
|
||||
test_arcane_SLASH_typeof();
|
||||
|
@ -67,47 +71,15 @@ int main()
|
|||
test_PLUS();
|
||||
test_MINUS();
|
||||
|
||||
struct Object *const sym_foo = Object_new_symbol("foo");
|
||||
struct Object *const sharp_true = Object_new_boolean(true);
|
||||
struct Object *const num_123 = Object_new_number(123);
|
||||
|
||||
// #true
|
||||
// #true
|
||||
assert(eval(sharp_true) == sharp_true);
|
||||
assert(Object_is_true(eval_str("#true")));
|
||||
|
||||
// 123
|
||||
// 123
|
||||
assert(eval(num_123) == num_123);
|
||||
|
||||
// (quote foo)
|
||||
// foo
|
||||
assert(
|
||||
eval(
|
||||
Object_build_list(2, Object_new_symbol("quote"), sym_foo)
|
||||
) == sym_foo
|
||||
);
|
||||
|
||||
// (quote #true)
|
||||
// #true
|
||||
assert(
|
||||
eval(
|
||||
Object_build_list(2, Object_new_symbol("quote"), sharp_true)
|
||||
) == sharp_true
|
||||
);
|
||||
|
||||
// (quote ())
|
||||
// ()
|
||||
assert(eval_str("(quote ())") == NULL);
|
||||
|
||||
// (quote 123)
|
||||
// 123
|
||||
assert(
|
||||
eval(
|
||||
Object_build_list(2, Object_new_symbol("quote"), num_123)
|
||||
) == num_123
|
||||
);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
result = eval_str("123");
|
||||
assert(Object_is_number(result));
|
||||
assert(result->number.i64 == 123);
|
||||
}
|
||||
|
||||
/**********
|
||||
|
@ -116,8 +88,6 @@ int main()
|
|||
|
||||
void test_begin()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (begin)
|
||||
// ()
|
||||
assert(OBJECT_IS_NULL(eval_str("(begin)")));
|
||||
|
@ -143,32 +113,158 @@ void test_begin()
|
|||
|
||||
void test_if()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (if #true 123 456)
|
||||
// 123
|
||||
result = eval_str("(if #true 123 456)");
|
||||
assert(Object_is_number(result));
|
||||
assert(result->number.i64 == 123);
|
||||
|
||||
// (if "foo" 123 456)
|
||||
// 123
|
||||
result = eval_str("(if \"foo\" 123 456)");
|
||||
assert(Object_is_number(result));
|
||||
assert(result->number.i64 == 123);
|
||||
|
||||
// (if #false 123 456)
|
||||
// 456
|
||||
result = eval_str("(if #false 123 456)");
|
||||
assert(Object_is_number(result));
|
||||
assert(result->number.i64 == 456);
|
||||
}
|
||||
|
||||
void test_quote()
|
||||
{
|
||||
// (quote +)
|
||||
// +
|
||||
result = eval_str("(quote +)");
|
||||
assert(Object_is_symbol(result));
|
||||
assert(strcmp(result->s, "+") == 0);
|
||||
|
||||
// '+
|
||||
// +
|
||||
result = eval_str("'+");
|
||||
assert(Object_is_symbol(result));
|
||||
assert(strcmp(result->s, "+") == 0);
|
||||
|
||||
// (quote ())
|
||||
// ()
|
||||
assert(OBJECT_IS_NULL(eval_str("(quote ())")));
|
||||
|
||||
// '()
|
||||
// ()
|
||||
assert(OBJECT_IS_NULL(eval_str("'()")));
|
||||
|
||||
// (quote #true)
|
||||
// #true
|
||||
result = eval_str("(quote #true)");
|
||||
assert(Object_is_true(result));
|
||||
|
||||
// '#true
|
||||
// #true
|
||||
result = eval_str("'#true");
|
||||
assert(Object_is_true(result));
|
||||
|
||||
// (quote #false)
|
||||
// #false
|
||||
result = eval_str("(quote #false)");
|
||||
assert(Object_is_false(result));
|
||||
|
||||
// '#false
|
||||
// #false
|
||||
result = eval_str("'#false");
|
||||
assert(Object_is_false(result));
|
||||
|
||||
// (quote #\n)
|
||||
// #\n
|
||||
result = eval(Object_build_list(
|
||||
2,
|
||||
Object_new_symbol("quote"),
|
||||
Object_new_char('\n')
|
||||
));
|
||||
assert(Object_is_char(result));
|
||||
assert(result->chr == '\n');
|
||||
|
||||
// '#\n
|
||||
// #\n
|
||||
result = eval(Object_build_list(
|
||||
2,
|
||||
Object_new_symbol("quote"),
|
||||
Object_new_char('\n')
|
||||
));
|
||||
assert(Object_is_char(result));
|
||||
assert(result->chr == '\n');
|
||||
|
||||
// (quote foo)
|
||||
// foo
|
||||
result = eval_str("(quote foo)");
|
||||
assert(Object_is_symbol(result));
|
||||
assert(strcmp(result->s, "foo") == 0);
|
||||
|
||||
// 'foo
|
||||
// foo
|
||||
result = eval_str("'foo");
|
||||
assert(Object_is_symbol(result));
|
||||
assert(strcmp(result->s, "foo") == 0);
|
||||
|
||||
// (quote "foo")
|
||||
// "foo"
|
||||
result = eval_str("(quote \"foo\")");
|
||||
assert(Object_is_string(result));
|
||||
assert(strcmp(result->s, "foo") == 0);
|
||||
|
||||
// '"foo"
|
||||
// "foo"
|
||||
result = eval_str("'\"foo\"");
|
||||
assert(Object_is_string(result));
|
||||
assert(strcmp(result->s, "foo") == 0);
|
||||
|
||||
// (quote 123)
|
||||
// 123
|
||||
result = eval_str("(quote 123)");
|
||||
assert(Object_is_number(result));
|
||||
assert(result->number.i64 == 123);
|
||||
|
||||
// '123
|
||||
// 123
|
||||
result = eval_str("'123");
|
||||
assert(Object_is_number(result));
|
||||
assert(result->number.i64 == 123);
|
||||
|
||||
// (quote (cons 123 456))
|
||||
// (cons 123 456)
|
||||
result = eval_str("(quote (cons 123 456))");
|
||||
assert(Object_is_pair(result));
|
||||
assert(Object_is_pair(result->pair.cdr));
|
||||
assert(Object_is_pair(result->pair.cdr->pair.cdr));
|
||||
assert(OBJECT_IS_NULL(result->pair.cdr->pair.cdr->pair.cdr));
|
||||
assert(Object_is_symbol(result->pair.car));
|
||||
assert(Object_is_number(result->pair.cdr->pair.car));
|
||||
assert(Object_is_number(result->pair.cdr->pair.cdr->pair.car));
|
||||
assert(strcmp(result->pair.car->s, "cons") == 0);
|
||||
assert(result->pair.cdr->pair.car->number.i64 == 123);
|
||||
assert(result->pair.cdr->pair.cdr->pair.car->number.i64 == 456);
|
||||
|
||||
// '(cons 123 456)
|
||||
// (cons 123 456)
|
||||
result = eval_str("'(cons 123 456)");
|
||||
assert(Object_is_pair(result));
|
||||
assert(Object_is_pair(result->pair.cdr));
|
||||
assert(Object_is_pair(result->pair.cdr->pair.cdr));
|
||||
assert(OBJECT_IS_NULL(result->pair.cdr->pair.cdr->pair.cdr));
|
||||
assert(Object_is_symbol(result->pair.car));
|
||||
assert(Object_is_number(result->pair.cdr->pair.car));
|
||||
assert(Object_is_number(result->pair.cdr->pair.cdr->pair.car));
|
||||
assert(strcmp(result->pair.car->s, "cons") == 0);
|
||||
assert(result->pair.cdr->pair.car->number.i64 == 123);
|
||||
assert(result->pair.cdr->pair.cdr->pair.car->number.i64 == 456);
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Arcane Scheme Lisp internals *
|
||||
********************************/
|
||||
|
||||
void test_arcane_SLASH_tokenize()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (arcane/tokenize "(")
|
||||
// ((TOKEN_ROUND_OPEN . ""))
|
||||
result = eval_str("(arcane/tokenize \"(\")");
|
||||
|
@ -286,8 +382,6 @@ void test_arcane_SLASH_tokenize()
|
|||
|
||||
void test_arcane_SLASH_typeof()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (arcane/typeof '())
|
||||
// null
|
||||
result = eval_str("(arcane/typeof '())");
|
||||
|
@ -347,8 +441,6 @@ void test_arcane_SLASH_typeof()
|
|||
|
||||
void test_car()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (car (cons 123 456))
|
||||
// 123
|
||||
result = eval_str("(car (cons 123 456))");
|
||||
|
@ -358,8 +450,6 @@ void test_car()
|
|||
|
||||
void test_cdr()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (cdr (cons 123 456))
|
||||
// 456
|
||||
result = eval_str("(cdr (cons 123 456))");
|
||||
|
@ -369,8 +459,6 @@ void test_cdr()
|
|||
|
||||
void test_list()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (list)
|
||||
// ()
|
||||
assert(eval_str("(list)") == NULL);
|
||||
|
@ -749,8 +837,6 @@ void test_symbolQN()
|
|||
|
||||
void test_number_TO_string()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (number->string 123)
|
||||
// "123"
|
||||
result = eval_str("(number->string 123)");
|
||||
|
@ -776,8 +862,6 @@ void test_number_TO_string()
|
|||
|
||||
void test_string_TO_symbol()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (string->symbol "")
|
||||
// ||
|
||||
result = eval_str("(string->symbol \"\")");
|
||||
|
@ -799,8 +883,6 @@ void test_string_TO_symbol()
|
|||
|
||||
void test_symbol_TO_string()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (symbol->string 'foo)
|
||||
// "foo"
|
||||
result = eval_str("(symbol->string 'foo)");
|
||||
|
@ -908,8 +990,6 @@ void test_EQ()
|
|||
|
||||
void test_PLUS()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (+)
|
||||
// 0
|
||||
result = eval_str("(+)");
|
||||
|
@ -943,8 +1023,6 @@ void test_PLUS()
|
|||
|
||||
void test_MINUS()
|
||||
{
|
||||
struct Object *result = NULL;
|
||||
|
||||
// (- 0)
|
||||
// 0
|
||||
result = eval_str("(- 0)");
|
||||
|
|
20
test.scm
20
test.scm
|
@ -14,6 +14,26 @@
|
|||
(displayln (if "foo" 123 456))
|
||||
(displayln (if #false 123 456))
|
||||
(newline)
|
||||
(displayln "--- TEST: quote ------------------------------------------------")
|
||||
(displayln (quote +))
|
||||
(displayln '+)
|
||||
(displayln (quote ()))
|
||||
(displayln '())
|
||||
(displayln (quote #true))
|
||||
(displayln '#true)
|
||||
(displayln (quote #false))
|
||||
(displayln '#false)
|
||||
'(displayln (quote "#\n"))
|
||||
'(displayln '"#\n")
|
||||
(displayln (quote foo))
|
||||
(displayln 'foo)
|
||||
(displayln (quote "foo"))
|
||||
(displayln '"foo")
|
||||
(displayln (quote 123))
|
||||
(displayln '123)
|
||||
(displayln (quote (cons 123 456)))
|
||||
(displayln '(cons 123 456))
|
||||
(newline)
|
||||
(displayln "=== GROUP: Arcane Scheme Lisp internals ========================")
|
||||
(newline)
|
||||
(displayln "--- TEST: arcane/tokenize --------------------------------------")
|
||||
|
|
18
test.txt
18
test.txt
|
@ -13,6 +13,24 @@
|
|||
123
|
||||
456
|
||||
|
||||
"--- TEST: quote ------------------------------------------------"
|
||||
+
|
||||
+
|
||||
()
|
||||
()
|
||||
#true
|
||||
#true
|
||||
#false
|
||||
#false
|
||||
foo
|
||||
foo
|
||||
"foo"
|
||||
"foo"
|
||||
123
|
||||
123
|
||||
(cons 123 456)
|
||||
(cons 123 456)
|
||||
|
||||
"=== GROUP: Arcane Scheme Lisp internals ========================"
|
||||
|
||||
"--- TEST: arcane/tokenize --------------------------------------"
|
||||
|
|
Loading…
Reference in New Issue