From f68558eca2e08d05cb861fff1818aa1ab0f8223e Mon Sep 17 00:00:00 2001 From: ahmedsamyh Date: Fri, 28 Feb 2025 10:55:15 +0500 Subject: [PATCH] [tests] New test string_view.c --- commonlib.h | 2 +- tests/string_view.c | 26 ++++++++++++++++++++++++++ tests/string_view.code.expected | 1 + tests/string_view.err.expected | 0 tests/string_view.out.expected | 6 ++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/string_view.c create mode 100644 tests/string_view.code.expected create mode 100644 tests/string_view.err.expected create mode 100644 tests/string_view.out.expected diff --git a/commonlib.h b/commonlib.h index 3571369..916ac3c 100644 --- a/commonlib.h +++ b/commonlib.h @@ -495,7 +495,7 @@ c_String_view c_sv_lpop_until_string(c_String_view* sv, const char *string) { while (sv->count > string_len) { bool matched = true; - for (int i = 0; i < string_len; ++i) { + for (size_t i = 0; i < string_len; ++i) { if (sv->data[i] != string[i]) matched = false; } if (matched) break; diff --git a/tests/string_view.c b/tests/string_view.c new file mode 100644 index 0000000..3815616 --- /dev/null +++ b/tests/string_view.c @@ -0,0 +1,26 @@ +#define COMMONLIB_IMPLEMENTATION +#define COMMONLIB_REMOVE_PREFIX +#include "../commonlib.h" + +int main(void) { + + String_view main = SV("Hello, World!"); + + String_view multiline_comment = SV("/*Blah Blah\nBlah Blah2\nTHis is the end*/THIS SHOULD NOT BE VISIBLE"); + + String_view mc = sv_lpop_until_string(&multiline_comment, "*/"); + + String_view a = sv_lpop_until_char(&main, ' '); + + sv_lremove(&main, 1); + + String_view b = main; + + log_info("main: '"SV_FMT"'", SV_ARG(main)); + log_info("a: '"SV_FMT"'", SV_ARG(a)); + log_info("b: '"SV_FMT"'", SV_ARG(b)); + + log_info("mc: '"SV_FMT"'", SV_ARG(mc)); + + return 0; +} diff --git a/tests/string_view.code.expected b/tests/string_view.code.expected new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/string_view.code.expected @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/string_view.err.expected b/tests/string_view.err.expected new file mode 100644 index 0000000..e69de29 diff --git a/tests/string_view.out.expected b/tests/string_view.out.expected new file mode 100644 index 0000000..6c289a1 --- /dev/null +++ b/tests/string_view.out.expected @@ -0,0 +1,6 @@ +[INFO] main: 'World!' +[INFO] a: 'Hello,' +[INFO] b: 'World!' +[INFO] mc: '/*Blah Blah +Blah Blah2 +THis is the end' -- 2.39.5