~donmcc/astr

cc29e35d495ccfdabd318928011647be1f092413 — Don McCaughey 1 year, 10 months ago d8397ad
Simplify definition of astr_alloc_empty() function.

Replace the call to `astr_alloc_format()` with a call to `calloc()`.

Also added an additional test for `astr_eq_bytes()` to test comparing
two empty strings.
2 files changed, 17 insertions(+), 1 deletions(-)

M astr.h
M astr_tests.c
M astr.h => astr.h +2 -1
@@ 4,6 4,7 @@

#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>




@@ 23,7 24,7 @@ astr_len_format_args(char const *format, va_list arguments);
inline char *
astr_alloc_empty(void)
{
    return astr_alloc_format("");
    return calloc(1, sizeof(char));
}

inline bool

M astr_tests.c => astr_tests.c +15 -0
@@ 62,6 62,20 @@ test_astr_eq_bytes_for_NULL_string(void)


static void
test_astr_eq_bytes_for_empty_strings(void)
{
    char *s1 = astr_alloc_empty();
    char *s2 = astr_alloc_empty();

    assert(s1 != s2);
    assert(astr_eq_bytes(s1, s2));

    free(s2);
    free(s1);
}


static void
test_astr_len_format(void)
{
    errno = 0;


@@ 89,6 103,7 @@ main(int argc, char *argv[])
    test_astr_alloc_format_for_NULL_format();
    test_astr_eq_bytes();
    test_astr_eq_bytes_for_NULL_string();
    test_astr_eq_bytes_for_empty_strings();
    test_astr_len_format();
    test_astr_len_format_for_NULL_format();
    return EXIT_SUCCESS;