From 45ef1fa01a2975fe5ea3eac61ce05ecc0eb88344 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 5 Feb 2026 04:48:13 +0000 Subject: [PATCH] tests: Added string view suite sv_copy is the only function, but we may have others later. --- test/main.c | 2 ++ test/test_sv.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/test_sv.c diff --git a/test/main.c b/test/main.c index f4baf0b..5174da1 100644 --- a/test/main.c +++ b/test/main.c @@ -12,12 +12,14 @@ #include "./test.h" #include "./test_lisp_api.c" +#include "./test_sv.c" #include "./test_symtable.c" #include "./test_vec.c" test_suite_t SUITES[] = { SYMTABLE_SUITE, LISP_API_SUITE, + SV_SUITE, VEC_SUITE, }; diff --git a/test/test_sv.c b/test/test_sv.c new file mode 100644 index 0000000..50446df --- /dev/null +++ b/test/test_sv.c @@ -0,0 +1,52 @@ +/* test_sv.c: String View tests + * Created: 2026-02-05 + * Author: Aryadev Chavali + * License: See end of file + * Commentary: + */ + +#include +#include + +#include "./data.h" +#include "./test.h" + +void sv_copy_test(void) +{ + static_assert(ARRSIZE(unique_words) > 3, "Expected at least 3 unique words"); + for (u64 i = 0; i < 3; ++i) + { + sv_t word = SV((char *)unique_words[i], strlen(unique_words[i])); + sv_t copy = sv_copy(word); + TEST(word.data != copy.data, "%p != %p", word.data, copy.data); + TEST(word.size == copy.size, "%lu == %lu", word.size, copy.size); + TEST(strncmp(word.data, copy.data, copy.size) == 0, "`%s` == `%s`", + word.data, copy.data); + + // Obviously we can't just have this lying around. + free(copy.data); + } +} + +const test_fn TESTS_SV[] = { + MAKE_TEST_FN(sv_copy_test), +}; + +const test_suite_t SV_SUITE = { + .name = "String View Tests", + .tests = TESTS_SV, + .size = ARRSIZE(TESTS_SV), +}; + +/* Copyright (C) 2026 Aryadev Chavali + + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for + * details. + + * You may distribute and modify this code under the terms of the GNU General + * Public License Version 2, which you should have received a copy of along with + * this program. If not, please go to . + + */