From 7ea2195fcb961e5de077cce859d13f4f7b6c6153 Mon Sep 17 00:00:00 2001 From: Robear Selwans Date: Sun, 6 Oct 2024 23:43:56 +0300 Subject: [PATCH] Added test case for pushFmt and added str_test as a meson unit test Signed-off-by: Robear Selwans --- meson.build | 4 ++++ str_test.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/meson.build b/meson.build index 408cacc..0706824 100644 --- a/meson.build +++ b/meson.build @@ -32,6 +32,10 @@ headers_dep = declare_dependency( ] ) +# Tests +str_test = executable('str_test', 'str_test.c', dependencies: [str_dep]) +test('evstr', str_test) + if meson.version().version_compare('>= 0.54.0') meson.override_dependency('ev_vec', vec_dep) meson.override_dependency('ev_str', str_dep) diff --git a/str_test.c b/str_test.c index 3bb5e21..5236f9c 100644 --- a/str_test.c +++ b/str_test.c @@ -56,5 +56,26 @@ int main() assert(search_results[1].offset == 26); assert(search_results[2].offset == 56); + { // PushFmt Bug + printf("PushFmt Bug"); + evstring heap_str = evstring_new("Heap 'Hello, World!'"); + printf("Heap String: %s, Length: %llu\n", heap_str, evstring_getLength(heap_str)); + + evstring_error_t res = evstring_push(&heap_str, "%.05f", 1.0f); + printf("Push Fmt #1: %s, New Length: %llu\n", heap_str, evstring_getLength(heap_str)); + assert(evstring_getLength(heap_str) == 27); + assert(strcmp(heap_str, "Heap 'Hello, World!'1.00000") == 0); + assert(res == EV_STR_ERR_NONE); + + /*evstring_push(&heap_str, "%.05f, %.05f, %.05f", 1.0f, 2.0f, 3.0f);*/ + res = evstring_push(&heap_str, "Something"); + printf("Push Fmt #2: %s, New Length: %llu\n", heap_str, evstring_getLength(heap_str)); + assert(evstring_getLength(heap_str) == 36); + assert(strcmp(heap_str, "Heap 'Hello, World!'1.00000Something") == 0); + assert(res == EV_STR_ERR_NONE); + + evstring_free(heap_str); + } + return 0; }