From e8d922d09df83ce8b4e3594a4809de204f1ac79a Mon Sep 17 00:00:00 2001 From: Mosder Date: Tue, 15 Sep 2026 19:25:54 +0200 Subject: formatting: formatted against new .clang-format --- tests/ds/array_tests.c | 37 +++++++++++++++---- tests/ds/hashmap_tests.c | 21 ++++++++--- tests/string_tests.c | 96 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 118 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/ds/array_tests.c b/tests/ds/array_tests.c index c5d7c4d..975443c 100644 --- a/tests/ds/array_tests.c +++ b/tests/ds/array_tests.c @@ -16,10 +16,16 @@ TEST(cap_test) { test_assert(arr_cap(arr) == 2 * MOS_ARR_INIT_CAP, "capacity didn't increase 2 times"); size_t new_cap = arr_set_cap(arr, 3 * MOS_ARR_INIT_CAP); - test_assert(new_cap == arr_cap(arr) && new_cap == 3 * MOS_ARR_INIT_CAP, "set cap didn't set correct capacity (cap >= len)"); + test_assert( + new_cap == arr_cap(arr) && new_cap == 3 * MOS_ARR_INIT_CAP, + "set cap didn't set correct capacity (cap >= len)" + ); new_cap = arr_set_cap(arr, 0); - test_assert(new_cap == arr_cap(arr) && new_cap == MOS_ARR_INIT_CAP + 1, "set cap didn't set correct capacity (cap < len)"); + test_assert( + new_cap == arr_cap(arr) && new_cap == MOS_ARR_INIT_CAP + 1, + "set cap didn't set correct capacity (cap < len)" + ); arr_free(arr); } @@ -95,10 +101,14 @@ TEST(getting_items) { test_assert(arr_last(arr) == NULL, "last of empty array isn't null"); arr_append(arr, (struct test){0}); - test_assert(arr_first(arr) == arr_last(arr), "first and last are different for array of length 1"); + test_assert( + arr_first(arr) == arr_last(arr), "first and last are different for array of length 1" + ); arr_append(arr, (struct test){1, 1}); - test_assert(arr_first(arr) != arr_last(arr), "first and last are the same for array of length >1"); + test_assert( + arr_first(arr) != arr_last(arr), "first and last are the same for array of length >1" + ); struct test *next_first = arr_next(arr, NULL); struct test *next_last = arr_next(arr, next_first); @@ -108,15 +118,24 @@ TEST(getting_items) { struct test *prev_null = arr_prev(arr, prev_first); test_assert(next_first && next_last, "next gave NULL when it shouldn't have"); test_assert(prev_first && prev_last, "prev gave NULL when it shouldn't have"); - test_assert(next_first == prev_first && next_last == prev_last, "next and prev gave different values for the same element"); + test_assert( + next_first == prev_first && next_last == prev_last, + "next and prev gave different values for the same element" + ); test_assert(!next_null, "next didn't give NULL after running out of items"); test_assert(!prev_null, "prev didn't give NULL after running out of items"); - test_assert(arr_get(arr, -1) == NULL && arr_get(arr, 2) == NULL, "arr_get didn't give NULL when out of bounds"); + test_assert( + arr_get(arr, -1) == NULL && arr_get(arr, 2) == NULL, + "arr_get didn't give NULL when out of bounds" + ); struct test i0 = *arr_get(arr, 0); struct test i1 = *arr_get(arr, 1); - test_assert(!memcmp(&i0, &arr[0], sizeof(struct test)) && !memcmp(&i1, &arr[1], sizeof(struct test)), "arr_get(arr, i) gives different result than arr[i]"); + test_assert( + !memcmp(&i0, &arr[0], sizeof(struct test)) && !memcmp(&i1, &arr[1], sizeof(struct test)), + "arr_get(arr, i) gives different result than arr[i]" + ); arr_free(arr); } @@ -176,7 +195,9 @@ TEST(arr_concat_test) { test_assert(index == 2, "arr_concat returned wrong index"); unsigned long expected[] = {4, 5, 1, 2, 3, 4, 5}; test_assert(arr_len(arr2) == 7, "arr_concat produced array of wrong length"); - test_assert(!memcmp(arr2, expected, 7 * sizeof(unsigned long)), "arr_concat produced wrong array"); + test_assert( + !memcmp(arr2, expected, 7 * sizeof(unsigned long)), "arr_concat produced wrong array" + ); arr_free(arr1); arr_free(arr2); diff --git a/tests/ds/hashmap_tests.c b/tests/ds/hashmap_tests.c index 4c615a7..268bc29 100644 --- a/tests/ds/hashmap_tests.c +++ b/tests/ds/hashmap_tests.c @@ -45,13 +45,19 @@ TEST(put_e_get_e) { hm_put_e(hm, (E){0.0f, 69}); hm_put_e(hm, (E){1.0f, 420}); E e = {0.0f, 69}; - test_assert(memcmp(&e, hm_get_e(hm, 0.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e"); + test_assert( + memcmp(&e, hm_get_e(hm, 0.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e" + ); e = (E){1.0f, 420}; - test_assert(memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e"); + test_assert( + memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e" + ); e = (E){1.0f, 2137}; hm_put_e(hm, e); - test_assert(memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_put_e didn't update entry properly"); + test_assert( + memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_put_e didn't update entry properly" + ); hm_free(hm); } @@ -137,7 +143,9 @@ TEST(looping) { E items[] = {{1, 10}, {2, 20}, {3, 30}}; arr_append_n(allowed, items, 3); - test_assert(memcmp(hm_first(hm), hm_next(hm, NULL), sizeof(E)) == 0, "hm_next(hm, NULL) != hm_first(hm)"); + test_assert( + memcmp(hm_first(hm), hm_next(hm, NULL), sizeof(E)) == 0, "hm_next(hm, NULL) != hm_first(hm)" + ); E *e = NULL; while ((e = hm_next(hm, e))) { int flag = 0; @@ -150,7 +158,10 @@ TEST(looping) { } test_assert(flag, "hm_next produced an entry that wasn't put in the hashmap"); } - test_assert(arr_len(allowed) == 0, "hm_next didn't produce every entry from hashmap when it looped over it"); + test_assert( + arr_len(allowed) == 0, + "hm_next didn't produce every entry from hashmap when it looped over it" + ); arr_free(allowed); hm_free(hm); diff --git a/tests/string_tests.c b/tests/string_tests.c index 0d0d7e2..f600400 100644 --- a/tests/string_tests.c +++ b/tests/string_tests.c @@ -26,7 +26,9 @@ TEST(creating) { test_assert(ss3.data == str && ss3.len == str_len, "ss_from_vars created wrong slice"); StringSlice ss4 = SS_LIT(HELLO_WORLD_LIT); - test_assert(ss4.data == str && ss4.len == sizeof(HELLO_WORLD_LIT) - 1, "SS_LIT created wrong slice"); + test_assert( + ss4.data == str && ss4.len == sizeof(HELLO_WORLD_LIT) - 1, "SS_LIT created wrong slice" + ); StringSlice ss5 = ss_copy(ss1); test_assert(ss5.data == ss1.data && ss5.len == ss1.len, "ss_from_arr created wrong slice"); @@ -58,11 +60,15 @@ TEST(comparing) { free(hw); StringSlice ss3 = ss_from_vars(ss.data, ss.len - 1); - test_assert(ss_eq(ss, ss3) == 0, "slice is equal when the pointer is the same but length differs"); + test_assert( + ss_eq(ss, ss3) == 0, "slice is equal when the pointer is the same but length differs" + ); StringSlice ss4 = ss_from_str("hello"); StringSlice ss5 = ss_from_str("world"); - test_assert(ss_eq(ss4, ss5) == 0, "slice is equal when the length is the same but pointer differs"); + test_assert( + ss_eq(ss4, ss5) == 0, "slice is equal when the length is the same but pointer differs" + ); test_assert(ss_eq_str(ss4, "world") == 0, "slice is equal to different string"); } @@ -86,7 +92,9 @@ TEST(trimming) { TEST(prefix_suffix) { StringSlice ss = ss_from_str("pre mid suf"); - test_assert(ss_starts_with(ss, ss_from_str("pre")), "slice doesn't start with its slice prefix"); + test_assert( + ss_starts_with(ss, ss_from_str("pre")), "slice doesn't start with its slice prefix" + ); test_assert(ss_starts_with(ss, ss_from_str("suf")) == 0, "slice starts with not slice prefix"); test_assert(ss_ends_with(ss, ss_from_str("suf")), "slice doesn't end with its slice suffix"); @@ -99,7 +107,9 @@ TEST(prefix_suffix) { test_assert(ss_ends_with_str(ss, "pre") == 0, "slice ends with not string suffix"); StringSlice ss2 = ss_from_str(""); - test_assert(ss_starts_with(ss2, ss_from_str("")), "starts_with breaks for empty slice and prefix"); + test_assert( + ss_starts_with(ss2, ss_from_str("")), "starts_with breaks for empty slice and prefix" + ); test_assert(ss_ends_with(ss2, ss_from_str("")), "ends_with breaks for empty slice and suffix"); } @@ -151,7 +161,9 @@ TEST(splitting) { StringSlice ss1 = ss_from_str("Hello, World!"); StringSlice ss2 = ss_split(&ss1, ','); - test_assert(ss_eq_str(ss2, "Hello") && ss_eq_str(ss1, " World!"), "ss_split didn't split proprely"); + test_assert( + ss_eq_str(ss2, "Hello") && ss_eq_str(ss1, " World!"), "ss_split didn't split proprely" + ); StringSlice ss3 = ss_split_str(&ss2, "ll"); test_assert(ss_eq_str(ss3, "He") && ss_eq_str(ss2, "o"), "ss_split_str didn't split proprely"); @@ -162,47 +174,85 @@ TEST(splitting) { ss1 = ss_from_str("hiii"); ss2 = ss_split_str(&ss1, ""); - test_assert(ss_eq_str(ss2, "") && ss_eq_str(ss1, "hiii"), "ss_split_str fails empty str edge case"); + test_assert( + ss_eq_str(ss2, "") && ss_eq_str(ss1, "hiii"), "ss_split_str fails empty str edge case" + ); ss2 = ss_split_ss(&ss1, SS_LIT("")); - test_assert(ss_eq_str(ss2, "") && ss_eq_str(ss1, "hiii"), "ss_split_ss fails empty ss edge case"); + test_assert( + ss_eq_str(ss2, "") && ss_eq_str(ss1, "hiii"), "ss_split_ss fails empty ss edge case" + ); ss2 = ss_split(&ss1, '.'); - test_assert(ss_eq_str(ss2, "hiii") && ss_eq_str(ss1, ""), "ss_split fails not found delim edge case"); + test_assert( + ss_eq_str(ss2, "hiii") && ss_eq_str(ss1, ""), "ss_split fails not found delim edge case" + ); ss1 = ss_split_str(&ss2, ".."); - test_assert(ss_eq_str(ss1, "hiii") && ss_eq_str(ss2, ""), "ss_split_str fails not found delim edge case"); + test_assert( + ss_eq_str(ss1, "hiii") && ss_eq_str(ss2, ""), "ss_split_str fails not found delim edge case" + ); ss2 = ss_split_ss(&ss1, SS_LIT("...")); - test_assert(ss_eq_str(ss2, "hiii") && ss_eq_str(ss1, ""), "ss_split_ss fails not found delim edge case"); + test_assert( + ss_eq_str(ss2, "hiii") && ss_eq_str(ss1, ""), "ss_split_ss fails not found delim edge case" + ); StringSlice ss_middle = ss_from_str("[left][middle][right]"); StringSlice ss_left = ss_split_left(&ss_middle, 6); - test_assert(ss_eq_str(ss_left, "[left]") && ss_eq_str(ss_middle, "[middle][right]"), "ss_split_left didn't split properly"); + test_assert( + ss_eq_str(ss_left, "[left]") && ss_eq_str(ss_middle, "[middle][right]"), + "ss_split_left didn't split properly" + ); StringSlice ss_right = ss_split_right(&ss_middle, 7); - test_assert(ss_eq_str(ss_right, "[right]") && ss_eq_str(ss_middle, "[middle]"), "ss_split_right didn't split properly"); + test_assert( + ss_eq_str(ss_right, "[right]") && ss_eq_str(ss_middle, "[middle]"), + "ss_split_right didn't split properly" + ); ss_left = ss_split_left(&ss_middle, 20); - test_assert(ss_eq_str(ss_left, "[middle]") && ss_eq_str(ss_middle, ""), "ss_split_left didn't split properly (n > len)"); + test_assert( + ss_eq_str(ss_left, "[middle]") && ss_eq_str(ss_middle, ""), + "ss_split_left didn't split properly (n > len)" + ); ss_right = ss_split_right(&ss_middle, 500); - test_assert(ss_eq_str(ss_right, "") && ss_eq_str(ss_middle, ""), "ss_split_right didn't split properly (n > len)"); + test_assert( + ss_eq_str(ss_right, "") && ss_eq_str(ss_middle, ""), + "ss_split_right didn't split properly (n > len)" + ); } TEST(finding) { char *txt = "a slice of FINDME text"; StringSlice ss = ss_from_str(txt); - test_assert(ss_eq_str(ss_find(ss, ss_from_str("FINDME")), "FINDME text"), "find didn't find a part of the slice"); - test_assert(ss_eq_str(ss_find_str(ss, "FINDME"), "FINDME text"), "find_str didn't find a part of the slice"); - - test_assert(ss_eq(ss_find(ss, ss_from_str("")), ss), "find didn't return whole slice for empty target"); - test_assert(ss_eq(ss_find_str(ss, ""), ss), "find_str didn't return whole slice for empty target"); - - test_assert(ss_eq_str(ss_find(ss, ss_from_str("abcd")), ""), "find didn't return empty slice for not found target"); - test_assert(ss_eq_str(ss_find_str(ss, "abcd"), ""), "find_str didn't return empty slice for not found target"); + test_assert( + ss_eq_str(ss_find(ss, ss_from_str("FINDME")), "FINDME text"), + "find didn't find a part of the slice" + ); + test_assert( + ss_eq_str(ss_find_str(ss, "FINDME"), "FINDME text"), + "find_str didn't find a part of the slice" + ); + + test_assert( + ss_eq(ss_find(ss, ss_from_str("")), ss), "find didn't return whole slice for empty target" + ); + test_assert( + ss_eq(ss_find_str(ss, ""), ss), "find_str didn't return whole slice for empty target" + ); + + test_assert( + ss_eq_str(ss_find(ss, ss_from_str("abcd")), ""), + "find didn't return empty slice for not found target" + ); + test_assert( + ss_eq_str(ss_find_str(ss, "abcd"), ""), + "find_str didn't return empty slice for not found target" + ); } TEST(utf8_len_test) { -- cgit v1.2.3