aboutsummaryrefslogtreecommitdiff
path: root/test/string.c
blob: 8a6742c6a93e6dc547d9281164fd028ddd71860a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include "kpl_test.h"

KPL_TEST(string_init) {
    kpl_thread thread = {};
    const char *c_string = "test string\n";
    kpl_memory_allocator_init(&thread.memory_allocator);
    kpl_gc_init(&thread.gc);
    kpl_object_string *string = kpl_object_string_from_c_string(&thread, c_string);
    KPL_ASSERT(string->bytes_length == (int32_t) strlen(c_string), "string should have same length as c string");
    KPL_ASSERT(strcmp(c_string, (char*) string->bytes) == 0, "new string should equal c string");
    kpl_gc_free(&thread);
    kpl_memory_allocator_free(&thread.memory_allocator);
}