summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/kit_test/test.c9
-rw-r--r--source/test/unittests/input_buffer.test.c39
2 files changed, 47 insertions, 1 deletions
diff --git a/source/kit_test/test.c b/source/kit_test/test.c
index 07c8871..0e8ca4b 100644
--- a/source/kit_test/test.c
+++ b/source/kit_test/test.c
@@ -144,5 +144,14 @@ int kit_run_tests(int argc, char **argv) {
status = 1;
}
+ if (status == 0) {
+ color_code(term_color, green);
+ printf("OK\n");
+ } else {
+ color_code(term_color, red);
+ printf("FAILED\n");
+ }
+
+ color_code(term_color, white);
return status;
}
diff --git a/source/test/unittests/input_buffer.test.c b/source/test/unittests/input_buffer.test.c
index a88b58b..175537c 100644
--- a/source/test/unittests/input_buffer.test.c
+++ b/source/test/unittests/input_buffer.test.c
@@ -3,7 +3,7 @@
#define KIT_TEST_FILE input_buffer
#include "../../kit_test/test.h"
-TEST("input buffer") {
+TEST("input buffer read once") {
str_t text = { .size = 3, .values = "foo" };
is_handle_t in = IS_WRAP_STRING(text);
ib_handle_t first = IB_WRAP(in);
@@ -18,3 +18,40 @@ TEST("input buffer") {
ib_destroy(first);
is_destroy(in);
}
+
+TEST("input buffer read again") {
+ str_t text = { .size = 6, .values = "foobar" };
+ str_t foo = { .size = 3, .values = "foo" };
+ is_handle_t in = IS_WRAP_STRING(text);
+ ib_handle_t first = IB_WRAP(in);
+
+ ib_handle_t second = ib_read(first, 3);
+ ib_handle_t third = ib_read(first, 3);
+
+ REQUIRE(AR_EQUAL(foo, second.data));
+ REQUIRE(AR_EQUAL(foo, third.data));
+
+ ib_destroy(third);
+ ib_destroy(second);
+ ib_destroy(first);
+ is_destroy(in);
+}
+
+TEST("input buffer read twice") {
+ str_t text = { .size = 6, .values = "foobar" };
+ str_t foo = { .size = 3, .values = "foo" };
+ str_t bar = { .size = 3, .values = "bar" };
+ is_handle_t in = IS_WRAP_STRING(text);
+ ib_handle_t first = IB_WRAP(in);
+
+ ib_handle_t second = ib_read(first, 3);
+ ib_handle_t third = ib_read(second, 3);
+
+ REQUIRE(AR_EQUAL(foo, second.data));
+ REQUIRE(AR_EQUAL(bar, third.data));
+
+ ib_destroy(third);
+ ib_destroy(second);
+ ib_destroy(first);
+ is_destroy(in);
+}