Skip to content

Commit

Permalink
More unit tests for mg_split()
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Feb 1, 2024
1 parent 8a96304 commit f8898b0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f8898b0

Please sign in to comment.