From f8898b016eaf14a5a557a9dcb5e7cb11df7b0462 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Thu, 1 Feb 2024 18:21:46 +0000 Subject: [PATCH] More unit tests for mg_split() --- test/unit_test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/unit_test.c b/test/unit_test.c index faceab48..6edeeb93 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -3259,11 +3259,28 @@ static void test_sha1(void) { test_sha1_str(")_)+_)!&^*%$#>>>{}}}{{{][[[[]]]", expected_hash_3); } + +static void test_split(void) { + struct mg_str k = mg_str_n("", 7), v = mg_str_n("", 8), s = mg_str(""); + ASSERT(mg_split(&s, &k, NULL, '.') == false); + ASSERT(mg_split(&s, &k, &v, '.') == false); + s = mg_str(""); + ASSERT(mg_split(&s, NULL, NULL, '.') == false); + s = mg_str("aa.bb"); + k = mg_str_n("", 7); + ASSERT(mg_split(&s, &k, NULL, '.') == true); + ASSERT(mg_strcmp(k, mg_str("aa")) == 0); + ASSERT(mg_split(&s, &k, NULL, '.') == true); + ASSERT(mg_strcmp(k, mg_str("bb")) == 0); + ASSERT(mg_split(&s, &k, NULL, '.') == false); +} + int main(void) { const char *debug_level = getenv("V"); if (debug_level == NULL) debug_level = "3"; mg_log_set(atoi(debug_level)); + test_split(); test_json(); test_queue(); test_rpc();