1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-30 23:23:07 +00:00

Adding some more unit tests for various components.

This commit is contained in:
bakpakin
2017-11-06 09:44:10 -05:00
parent f6dcb07c8d
commit 9a858d5a97
8 changed files with 88 additions and 43 deletions

View File

@@ -3,6 +3,7 @@
int main() {
int64_t i;
dst_init();
DstArray *array = dst_array(10);
assert(array->capacity == 10);
assert(array->count == 0);

19
unittests/buffer_test.c Normal file
View File

@@ -0,0 +1,19 @@
#include "unit.h"
#include <dst/dst.h>
int main() {
dst_init();
DstBuffer *buffer = dst_buffer(100);
assert(buffer->count == 0);
assert(buffer->capacity == 100);
dst_buffer_push_u8(buffer, 'h');
dst_buffer_push_u8(buffer, 'e');
dst_buffer_push_u8(buffer, 'l');
dst_buffer_push_u8(buffer, 'l');
dst_buffer_push_u8(buffer, 'o');
assert(dst_equals(
dst_wrap_string(dst_cstring("hello")),
dst_wrap_string(dst_string(buffer->data, buffer->count))
));
return 0;
}

15
unittests/table_test.c Normal file
View File

@@ -0,0 +1,15 @@
#include "unit.h"
#include <dst/dst.h>
int main() {
dst_init();
DstTable *table = dst_table(10);
assert(table->count == 0);
dst_table_put(table, dst_cstringv("a"), dst_cstringv("b"));
dst_table_put(table, dst_cstringv("b"), dst_cstringv("a"));
dst_table_put(table, dst_cstringv("a"), dst_cstringv("c"));
assert(table->count == 2);
dst_table_remove(table, dst_cstringv("a"));
assert(table->count == 1);
return 0;
}