You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
3 years ago
|
#include "ptlisp-test.h"
|
||
|
#include "../src/lisp.h"
|
||
|
|
||
|
START_TEST(str_create_test) {
|
||
|
char chars[] = "Hello, world!";
|
||
|
size_t size = sizeof(chars);
|
||
|
Pointer str = string(chars, size);
|
||
|
|
||
|
ck_assert_uint_eq(STRING(str).length, size);
|
||
|
for (size_t i = 0; i < size; i++) {
|
||
|
ck_assert_uint_eq(STRING(str).data[i], chars[i]);
|
||
|
}
|
||
|
}
|
||
|
END_TEST
|
||
|
|
||
|
START_TEST(str_push_test) {
|
||
|
char chars[] = "Hello, world!";
|
||
|
size_t size = sizeof(chars);
|
||
|
Pointer str = string(chars, size);
|
||
|
string_push(str, '?');
|
||
|
|
||
|
ck_assert_uint_eq(STRING(str).length, size + 1);
|
||
|
for (unsigned i = 0; i < size; i++) {
|
||
|
ck_assert_uint_eq(STRING(str).data[i], chars[i]);
|
||
|
}
|
||
|
|
||
|
ck_assert_uint_eq(STRING(str).data[size], '?');
|
||
|
}
|
||
|
END_TEST
|
||
|
|
||
|
static void setup(void) {
|
||
|
memory_init(16);
|
||
|
}
|
||
|
|
||
|
static void teardown(void) {
|
||
|
memory_free();
|
||
|
}
|
||
|
|
||
|
Suite* make_string_test_suite(void) {
|
||
|
Suite *s1 = suite_create("String");
|
||
|
TCase *tc1_1 = tcase_create("String");
|
||
|
suite_add_tcase(s1, tc1_1);
|
||
|
|
||
|
tcase_add_checked_fixture(tc1_1, setup, teardown);
|
||
|
tcase_add_test(tc1_1, str_create_test);
|
||
|
tcase_add_test(tc1_1, str_push_test);
|
||
|
|
||
|
return s1;
|
||
|
}
|