diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/moslib/ds/array.h | 100 | ||||
| -rw-r--r-- | include/moslib/ds/hashmap.h | 64 | ||||
| -rw-r--r-- | include/moslib/string.h | 30 | ||||
| -rw-r--r-- | include/moslib/tester.h | 36 |
4 files changed, 129 insertions, 101 deletions
diff --git a/include/moslib/ds/array.h b/include/moslib/ds/array.h index 36acc03..cc0c174 100644 --- a/include/moslib/ds/array.h +++ b/include/moslib/ds/array.h @@ -1,8 +1,8 @@ // moslib/ds/array.h // Implementation of dynamic array -// ======================================== QUICK USAGE GUIDE ========================================= -// ---------------------------------------------------------------------------------------------------- +// ======================================= QUICK USAGE GUIDE ======================================= +// ------------------------------------------------------------------------------------------------- // // Define the dynamic array of type T as: // @@ -14,7 +14,7 @@ // // #define MOS_ARR_INIT_CAP <desired_init_cap> // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // You can access the items simply by array indexing: // @@ -29,7 +29,7 @@ // It will provide bounds checking - arr_get returning NULL when index is out of bounds // - both arr_first and arr_last returning NULL when array is empty // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To append/push to the array use: // @@ -46,15 +46,15 @@ // size_t index = arr_insert(array, i, item); // // It returns the index of the newly inserted item -// If index is greater or equal to array length then it functions identically to arr_append/arr_push. +// If index >= array length then it functions identically to arr_append/arr_push. // // To put into specific index (and update if value exists) use: // // size_t index = arr_put(array, i, item); // // It returns the index of the newly put item -// If index is greater or equal to array length it will extend the length to the put item and it will -// zero all items between previously last item to the new item. +// If index >= array length it will extend the length to the put item and it will zero all items +// between previously last item to the new item. // // If you want to add more items than 1 at once, you can use these: // @@ -65,7 +65,7 @@ // // They work the same way as their counterparts without n, but accept an array of items instead. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To concatenate two dynamic arrays of the same type use: // @@ -75,7 +75,7 @@ // Returns index of the first item of array2 in array1. // If array 2 is NULL or has length 0 - returns (size_t)-1. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To delete and retrieve the last item from an array use: // @@ -102,7 +102,7 @@ // // They work like arr_del_n without needing to specify the indices. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // You can use these to get a pointer to the previous or next item in array: // @@ -112,7 +112,7 @@ // When p_item is NULL it will return pointer to the last/first item. // When there's no prev/next item - it will return NULL. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To get array's current length use: // @@ -126,7 +126,7 @@ // If it's smaller than current length - it will delete items. // Returns amount of items deleted in this way. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To get array's current capacity use: // @@ -139,14 +139,14 @@ // When target_cap is lower than array length it will set capacity to array length. // Returns the new capacity. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To free the array from memory use: // // arr_free(array); // -// ---------------------------------------------------------------------------------------------------- -// ===================================== END OF QUICK USAGE GUIDE ===================================== +// ------------------------------------------------------------------------------------------------- +// ===================================== END OF QUICK USAGE GUIDE ================================== #include "moslib/safe.h" @@ -220,8 +220,6 @@ // pointer to the last item or NULL if array is empty #define mos_arr_last(arr) (mos_arr_len(arr) == 0 ? NULL : (arr) + mos_arr_len(arr) - 1) -// clang-format off - // Append a given item to the array // // Arguments: @@ -235,11 +233,10 @@ // Returns: // index of the appended item #define mos_arr_push mos_arr_append -#define mos_arr_append(arr, ...) ( \ - mos_arr_append_fn(&(arr), sizeof(*(arr)), MOS_ARR_INIT_CAP), \ - (arr)[mos_arr_len(arr) - 1] = __VA_ARGS__, \ - mos_arr_len(arr) - 1 \ -) +#define mos_arr_append(arr, ...) \ + (mos_arr_append_fn(&(arr), sizeof(*(arr)), MOS_ARR_INIT_CAP), \ + (arr)[mos_arr_len(arr) - 1] = __VA_ARGS__, \ + mos_arr_len(arr) - 1) // Insert a given item at the specific position in the array // Move everything after it to the right @@ -258,15 +255,12 @@ // // Returns: // index of the inserted item -#define mos_arr_insert(arr, i, ...) ( \ - (size_t)(i) >= mos_arr_len(arr) ? ( \ - mos_arr_append(arr, __VA_ARGS__) \ - ) : ( \ - mos_arr_insert_fn(&(arr), i, sizeof(*(arr)), MOS_ARR_INIT_CAP), \ - (arr)[(size_t)(i)] = __VA_ARGS__, \ - (size_t)(i) \ - ) \ -) +#define mos_arr_insert(arr, i, ...) \ + ((size_t)(i) >= mos_arr_len(arr) \ + ? (mos_arr_append(arr, __VA_ARGS__)) \ + : (mos_arr_insert_fn(&(arr), i, sizeof(*(arr)), MOS_ARR_INIT_CAP), \ + (arr)[(size_t)(i)] = __VA_ARGS__, \ + (size_t)(i))) // Put a given item at the specific position in the array // If index is within array bounds - it overwrites the item at given spot @@ -286,13 +280,10 @@ // // Returns: // index of the put item -#define mos_arr_put(arr, i, ...) ( \ - mos_arr_put_fn(&(arr), i, sizeof(*(arr)), MOS_ARR_INIT_CAP), \ - (arr)[(size_t)(i)] = __VA_ARGS__, \ - (size_t)(i) \ -) - -// clang-format on +#define mos_arr_put(arr, i, ...) \ + (mos_arr_put_fn(&(arr), i, sizeof(*(arr)), MOS_ARR_INIT_CAP), \ + (arr)[(size_t)(i)] = __VA_ARGS__, \ + (size_t)(i)) // Append n given items to the array // @@ -309,7 +300,8 @@ // Returns: // index of the first appended item #define mos_arr_push_n mos_arr_append_n -#define mos_arr_append_n(arr, items, n) mos_arr_append_n_fn(&(arr), items, n, sizeof(*(arr)), MOS_ARR_INIT_CAP) +#define mos_arr_append_n(arr, items, n) \ + mos_arr_append_n_fn(&(arr), items, n, sizeof(*(arr)), MOS_ARR_INIT_CAP) // Insert n given items at the specific position in the array // Move everything after them to the right @@ -330,7 +322,8 @@ // // Returns: // index of the first inserted item -#define mos_arr_insert_n(arr, i, items, n) mos_arr_insert_n_fn(&(arr), i, items, n, sizeof(*(arr)), MOS_ARR_INIT_CAP) +#define mos_arr_insert_n(arr, i, items, n) \ + mos_arr_insert_n_fn(&(arr), i, items, n, sizeof(*(arr)), MOS_ARR_INIT_CAP) // Put n given items at the specific position in the array // If index is within array bounds - it overwrites the items at given spots @@ -352,7 +345,8 @@ // // Returns: // index of the first put item -#define mos_arr_put_n(arr, i, items, n) mos_arr_put_n_fn(&(arr), i, items, n, sizeof(*(arr)), MOS_ARR_INIT_CAP) +#define mos_arr_put_n(arr, i, items, n) \ + mos_arr_put_n_fn(&(arr), i, items, n, sizeof(*(arr)), MOS_ARR_INIT_CAP) // Concatenate two dynamic arrays of the same type // @@ -365,7 +359,8 @@ // // Returns: // index of the first new item in arr1 or (size_t)-1 if arr2 is NULL or has length 0 -#define mos_arr_concat(arr1, arr2) mos_arr_concat_fn(&(arr1), arr2, sizeof(*(arr1)), MOS_ARR_INIT_CAP) +#define mos_arr_concat(arr1, arr2) \ + mos_arr_concat_fn(&(arr1), arr2, sizeof(*(arr1)), MOS_ARR_INIT_CAP) // Delete and retrieve the last item from the array // No bounds checking @@ -448,7 +443,10 @@ // // Returns: // pointer to the previous item or NULL if there's no more items -#define mos_arr_prev(arr, curr) ((!(arr) || !(curr)) ? mos_arr_last(arr) : ((curr) == mos_arr_first(arr) ? NULL : (arr) + mos_arr_p_diff(curr, arr) - 1)) +#define mos_arr_prev(arr, curr) \ + ((!(arr) || !(curr)) \ + ? mos_arr_last(arr) \ + : ((curr) == mos_arr_first(arr) ? NULL : (arr) + mos_arr_p_diff(curr, arr) - 1)) // Get the pointer to the next item in the array from the pointer to the current one // If pointer is NULL - gets the first item from the array @@ -462,7 +460,10 @@ // // Returns: // pointer to the next item or NULL if there's no more items -#define mos_arr_next(arr, curr) ((!(arr) || !(curr)) ? mos_arr_first(arr) : ((curr) == mos_arr_last(arr) ? NULL : (arr) + mos_arr_p_diff(curr, arr) + 1)) +#define mos_arr_next(arr, curr) \ + ((!(arr) || !(curr)) \ + ? mos_arr_first(arr) \ + : ((curr) == mos_arr_last(arr) ? NULL : (arr) + mos_arr_p_diff(curr, arr) + 1)) // Get the length of the array // @@ -526,9 +527,14 @@ extern void mos_arr_free(void *arr); extern void mos_arr_append_fn(void *p_arr, size_t el_size, size_t init_cap); extern void mos_arr_insert_fn(void *p_arr, size_t i, size_t el_size, size_t init_cap); extern void mos_arr_put_fn(void *p_arr, size_t i, size_t el_size, size_t init_cap); -extern size_t mos_arr_append_n_fn(void *p_arr, const void *items, size_t n, size_t el_size, size_t init_cap); -extern size_t mos_arr_insert_n_fn(void *p_arr, size_t i, const void *items, size_t n, size_t el_size, size_t init_cap); -extern size_t mos_arr_put_n_fn(void *p_arr, size_t i, const void *items, size_t n, size_t el_size, size_t init_cap); +extern size_t +mos_arr_append_n_fn(void *p_arr, const void *items, size_t n, size_t el_size, size_t init_cap); +extern size_t mos_arr_insert_n_fn( + void *p_arr, size_t i, const void *items, size_t n, size_t el_size, size_t init_cap +); +extern size_t mos_arr_put_n_fn( + void *p_arr, size_t i, const void *items, size_t n, size_t el_size, size_t init_cap +); extern size_t mos_arr_concat_fn(void *p_arr, const void *arr2, size_t el_size, size_t init_cap); extern size_t mos_arr_del_fn(void *arr, size_t i, size_t el_size); extern size_t mos_arr_del_n_fn(void *arr, size_t i, size_t n, size_t el_size); diff --git a/include/moslib/ds/hashmap.h b/include/moslib/ds/hashmap.h index cd17d0f..09a27e2 100644 --- a/include/moslib/ds/hashmap.h +++ b/include/moslib/ds/hashmap.h @@ -1,8 +1,8 @@ // moslib/ds/hashmap.h // Implementation of hashmap -// ======================================== QUICK USAGE GUIDE ========================================= -// ---------------------------------------------------------------------------------------------------- +// ======================================= QUICK USAGE GUIDE ======================================= +// ------------------------------------------------------------------------------------------------- // // Start by defining an Entry struct: // @@ -36,8 +36,6 @@ // // .hash and .eq will overwrite the functions set by .key. // -// It's better to assign NULL than to call hm_new with no arguments when you don't redefine anything. -// // Examples: // // HM_DEF(str_int, char *, int); @@ -52,13 +50,13 @@ // HM_DEF(int_int, int, int); // int_int *hm3 = hm_new(.hash = hash_int); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To set the hashmap load factor, define (before including the header): // // #define MOS_HM_LOAD_FACTOR <desired_load_factor_in_%> // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To put a key/value pair or an entry into a hashmap use: // @@ -67,7 +65,7 @@ // // If an entry with the same key already exists - it will be overwritten. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To get a value from a hashmap use: // @@ -80,9 +78,9 @@ // struct Entry *entry = hm_get_e(hm, key); // // If an entry of given key is not in the hashmap it will return NULL. -// Note that hm_put, hm_put_e and hm_del might cause a rehash which will leave that pointer dangling. +// Note: hm_put, hm_put_e and hm_del might cause a rehash which will leave that pointer dangling. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To delete an an entry from a hashmap use: // @@ -97,7 +95,7 @@ // It works the same as hm_del - it just ensures no reallocation. // Useful when you want to delete entries while looping over them. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // You can loop over the hashmap using these functions: // @@ -106,28 +104,28 @@ // // hm_first will return the pointer to the "first entry" (with the lowest hash) in the hashmap. // If hashmap is empty - it will return NULL. -// Note that hm_put, hm_put_e and hm_del might cause a rehash which will leave that pointer dangling. +// Note: hm_put, hm_put_e and hm_del might cause a rehash which will leave that pointer dangling. // // hm_next returns the pointer to the next entry in the hashmap from the pointer to the current one. // If hashmap is empty - it will return NULL. // If curr is NULL - same as hm_first. // If curr is the last entry - it will return NULL. -// Note that hm_put, hm_put_e and hm_del might cause a rehash which will leave that pointer dangling. +// Note: hm_put, hm_put_e and hm_del might cause a rehash which will leave that pointer dangling. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To get the count of entries in the hashmap, use: // // hm_size(hm); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // Free the hashmap with: // // hm_free(hm); // -// ---------------------------------------------------------------------------------------------------- -// ===================================== END OF QUICK USAGE GUIDE ===================================== +// ------------------------------------------------------------------------------------------------- +// =================================== END OF QUICK USAGE GUIDE ==================================== #include <stddef.h> #include <stdint.h> @@ -166,10 +164,12 @@ typedef struct { int (*eq)(const void *key1, const void *key2); } MosHmNewArgs; -// clang-format off // Macro to define Entry struct easier -#define MOS_HM_DEF(name, key_t, val_t) typedef struct {key_t key; val_t val;} name -// clang-format on +#define MOS_HM_DEF(name, key_t, val_t) \ + typedef struct { \ + key_t key; \ + val_t val; \ + } name // Create a new hashmap // @@ -204,7 +204,11 @@ typedef struct { // ... // value of the entry to put // variadic to make things like (struct Val){1,1} work properly -#define mos_hm_put(hm, k, ...) (mos_hm_ini(hm), (hm)->val = __VA_ARGS__, (hm)->key = k, mos_hm_put_fn(&(hm), mos_hm_fn_args(hm), MOS_HM_LOAD_FACTOR)) +#define mos_hm_put(hm, k, ...) \ + (mos_hm_ini(hm), \ + (hm)->val = __VA_ARGS__, \ + (hm)->key = k, \ + mos_hm_put_fn(&(hm), mos_hm_fn_args(hm), MOS_HM_LOAD_FACTOR)) // Put a given entry in the hashmap // If entry of the same key exists - overwrites it @@ -216,7 +220,10 @@ typedef struct { // ... // entry to put into hashmap // variadic to make things like (struct Entry){"key","val"} work properly -#define mos_hm_put_e(hm, ...) (mos_hm_ini(hm), (hm)[0] = __VA_ARGS__, mos_hm_put_fn(&(hm), mos_hm_fn_args(hm), MOS_HM_LOAD_FACTOR)) +#define mos_hm_put_e(hm, ...) \ + (mos_hm_ini(hm), \ + (hm)[0] = __VA_ARGS__, \ + mos_hm_put_fn(&(hm), mos_hm_fn_args(hm), MOS_HM_LOAD_FACTOR)) // Get the value of entry with specific key // @@ -229,7 +236,8 @@ typedef struct { // // Returns: // value of the entry with given key or 0 if no such entry exist -#define mos_hm_get(hm, k) (mos_hm_ini(hm), (hm)->key = k, (hm)[mos_hm_get_fn(hm, mos_hm_fn_args(hm))].val) +#define mos_hm_get(hm, k) \ + (mos_hm_ini(hm), (hm)->key = k, (hm)[mos_hm_get_fn(hm, mos_hm_fn_args(hm))].val) // Get a pointer to an entry with specific key in hashmap // @@ -314,14 +322,20 @@ extern void mos_hm_init(void *p_hm, size_t entry_size); #define mos_hm_fn_args(hm) &(hm)->key, sizeof(*(hm)), sizeof((hm)->key) -#define mos_hm_del_(hm, k, reh) (mos_hm_ini(hm), (hm)->key = k, mos_hm_del_fn(&(hm), mos_hm_fn_args(hm), MOS_HM_LOAD_FACTOR, reh)) +#define mos_hm_del_(hm, k, reh) \ + (mos_hm_ini(hm), \ + (hm)->key = k, \ + mos_hm_del_fn(&(hm), mos_hm_fn_args(hm), MOS_HM_LOAD_FACTOR, reh)) // Function prototypes for macros extern void *mos_hm_new_fn(MosHmNewArgs args); -extern void mos_hm_put_fn(void *p_hm, void *key, size_t entry_size, size_t key_size, uint8_t load_factor); +extern void +mos_hm_put_fn(void *p_hm, void *key, size_t entry_size, size_t key_size, uint8_t load_factor); extern size_t mos_hm_get_fn(void *hm, void *key, size_t entry_size, size_t key_size); extern void *mos_hm_get_e_fn(void *hm, void *key, size_t entry_size, size_t key_size); -extern int mos_hm_del_fn(void *p_hm, void *key, size_t entry_size, size_t key_size, uint8_t load_factor, int reh); +extern int mos_hm_del_fn( + void *p_hm, void *key, size_t entry_size, size_t key_size, uint8_t load_factor, int reh +); extern void *mos_hm_first_fn(const void *hm, size_t entry_size); extern void *mos_hm_next_fn(const void *hm, const void *curr, size_t entry_size); diff --git a/include/moslib/string.h b/include/moslib/string.h index 165bdf7..65a38c5 100644 --- a/include/moslib/string.h +++ b/include/moslib/string.h @@ -1,8 +1,8 @@ // moslib/string.h // Length aware string slices -// ======================================== QUICK USAGE GUIDE ========================================= -// ---------------------------------------------------------------------------------------------------- +// ======================================= QUICK USAGE GUIDE ======================================= +// ------------------------------------------------------------------------------------------------- // // StringSlice is defined as a struct which contains a pointer to the beginning of a string and its // length: @@ -12,7 +12,7 @@ // size_t len; // } StringSlice; // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To get a string slice from a C string you can use: // @@ -45,7 +45,7 @@ // // StringSlice ss = ss_from_vars("[in][out]", 4); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To print a slice you can either use: // @@ -57,14 +57,14 @@ // // printf("Slice: " SS_FMT "\n", SS_ARGS(ss)); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To check if two slices / slice and string are equal, use: // // int are_eq = ss_eq(ss1, ss2); // int are_eq = ss_eq_str(ss1, "string"); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // You can trim a slice from whitespace using: // @@ -72,7 +72,7 @@ // StringSlice trimmed_l = ss_trim_left(ss); // StringSlice trimmed_r = ss_trim_right(ss); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To check whether a slice starts or ends with a slice / string, you can use: // @@ -81,7 +81,7 @@ // int flag = ss_starts_with_str(ss, str_prefix); // int flag = ss_ends_with_str(ss, str_suffix); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To delete from the left or the right, use: // @@ -100,7 +100,7 @@ // It will return whether or not the slice started / ended with the prefix / suffix and delete it if // it did. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // You can split a slice by a delimiter using ss_split functions: // @@ -123,27 +123,27 @@ // // It will return the "split" part and leave the remainder in the argument slice. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // To find within a slice a part which begins with given target, use: // // StringSlice target1 = ss_find(ss, ss_target); // StringSlice target2 = ss_find_str(ss, str_target); // -// The return value is a slice that begins at the beginning of the specified target and ends at the end -// of the original slice. +// The return value is a slice that begins at the beginning of the specified target and ends +// at the end of the original slice. // If the target was an emptry slice / string - returns the entire slice. // If the target was not found - returns empty slice. // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // If you want to get length of a slice then you can simply use the len field of the struct. // However, if you want to know the length which respects utf-8 encoding, use: // // size_t utf8_len = ss_utf8_len(ss); // -// ---------------------------------------------------------------------------------------------------- -// ===================================== END OF QUICK USAGE GUIDE ===================================== +// ------------------------------------------------------------------------------------------------- +// =================================== END OF QUICK USAGE GUIDE ==================================== #include <stddef.h> diff --git a/include/moslib/tester.h b/include/moslib/tester.h index f8cc8b1..9f3b482 100644 --- a/include/moslib/tester.h +++ b/include/moslib/tester.h @@ -1,8 +1,8 @@ // moslib/tester.h // Helper functions for writing and running tests -// ======================================== QUICK USAGE GUIDE ========================================= -// ---------------------------------------------------------------------------------------------------- +// ======================================= QUICK USAGE GUIDE ======================================= +// ------------------------------------------------------------------------------------------------- // // Define the tester: // @@ -14,13 +14,13 @@ // // Tester *tester = new_tester(); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // Add test groups: // // TestGroup *test_group = add_test_group(tester, group_name); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // Create tests. // They should use test_assert functions to check correctness. @@ -67,26 +67,26 @@ // test_assert(code == 0, "function didn't fail"); // } // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // Add tests to test group: // // add_test(test_group, test_fn); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // Run tests: // // int all_passed = run_tests(tester); // -// ---------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // Free tester: // // free_tester(tester); // -// ---------------------------------------------------------------------------------------------------- -// ===================================== END OF QUICK USAGE GUIDE ===================================== +// ------------------------------------------------------------------------------------------------- +// =================================== END OF QUICK USAGE GUIDE ==================================== #include <stdio.h> @@ -137,7 +137,8 @@ extern MosTester *mos_new_tester(void); // // Returns: // pointer to the added group -#define mos_add_test_group(tester, group_name) ((!(tester) ? (tester) = mos_new_tester() : 0), mos_add_test_group_fn(tester, group_name)) +#define mos_add_test_group(tester, group_name) \ + ((!(tester) ? (tester) = mos_new_tester() : 0), mos_add_test_group_fn(tester, group_name)) // Assert that an expression is true // Use in test functions to test correctness @@ -159,7 +160,7 @@ extern void mos_test_assert(int expression, const char *fail_message); // // code // expected exit code -#define mos_test_assert_exit(function, code) mos_test_assert_exit_fn(function, code, #function); +#define mos_test_assert_exit(function, code) mos_test_assert_exit_fn(function, code, #function) // Assert that function writes correct output to specified stream // @@ -172,7 +173,8 @@ extern void mos_test_assert(int expression, const char *fail_message); // // output // expected output of the function -#define mos_test_assert_out(function, stream, output) mos_test_assert_out_fn(function, stream, output, #function, #stream); +#define mos_test_assert_out(function, stream, output) \ + mos_test_assert_out_fn(function, stream, output, #function, #stream) // Suppress given output // @@ -193,7 +195,7 @@ extern void mos_unsuppress_outputs(void); // // test // test to add to the group -#define mos_add_test(group, test) mos_add_test_fn(group, test, #test); +#define mos_add_test(group, test) mos_add_test_fn(group, test, #test) // Run defined tests // @@ -215,7 +217,13 @@ extern void mos_free_tester(MosTester *tester); // Function prototypes for macros extern MosTestGroup *mos_add_test_group_fn(MosTester *tester, const char *group_name); extern void mos_test_assert_exit_fn(MosTestFn function, int code, const char *name); -extern void mos_test_assert_out_fn(MosTestFn function, FILE *stream, const char *output, const char *fn_name, const char *stream_name); +extern void mos_test_assert_out_fn( + MosTestFn function, + FILE *stream, + const char *output, + const char *fn_name, + const char *stream_name +); extern void mos_add_test_fn(MosTestGroup *group, MosTestFn test, const char *name); #endif // MOSLIB_TESTER_H |
