From 3ac08b039539f5cb3289cd33cb9f63fa9452d438 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 16 Jun 2021 22:33:36 +0200 Subject: [PATCH] Add test with a lot of different kind of M_LET with list of strings. --- m-string.h | 2 +- tests/test-mlist.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/m-string.h b/m-string.h index f717e721..29c7733b 100644 --- a/m-string.h +++ b/m-string.h @@ -1736,7 +1736,7 @@ string_utf8_p(string_t str) #ifndef __cplusplus /* Initialize a constant string with the given C string */ # define STRING_CTE(s) \ - ((const string_t){{.u.heap = { .size = sizeof(s)-1, .alloc = sizeof(s) } , \ + (string_srcptr)((const string_t){{.u.heap = { .size = sizeof(s)-1, .alloc = sizeof(s) } , \ .ptr = ((struct { long long _n; char _d[sizeof (s)]; }){ 0, s })._d }}) #else namespace m_lib { diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 216adb10..39f24c8c 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -39,6 +39,8 @@ LIST_DUAL_PUSH_DEF(list2_mpz, testobj_t, TESTOBJ_OPLIST) LIST_DEF(list_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear))) LIST_DUAL_PUSH_DEF(list2_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear))) +LIST_DEF(list_string, string_t) +#define M_OPL_list_string_t() LIST_OPLIST(list_string, STRING_OPLIST) LIST_DEF_AS(list_double, ListDouble, ListDoubleIt, double) #define M_OPL_ListDouble() LIST_OPLIST(list_double, M_DEFAULT_OPLIST) @@ -674,6 +676,31 @@ static void test_double(void) } } +static void test_let_string(void) +{ + M_LET( (y, ("!") ), string_t) // string_t y = string_t{"!"} + M_LET( (z, y), string_t) // string_t z = y + M_LET( (x, ("Hello"), ("%d World", 2), y ), list_string_t) // astr_t x = { string_t{"Hello"}, string_t{"World"}, z } + M_LET( (xx, x), list_string_t) // astr_t xx = x + M_LET( (zz, (("Hellno")) ), list_string_t) // astr_t zz = { string_t{"Hellno"} } + M_LET( (zx, (y) ), list_string_t) // astr_t zx = { z } + M_LET( (tab_name, STRING_CTE("My"), STRING_CTE("CD"), STRING_CTE("IS"), STRING_CTE("OUT")), list_string_t) + { + assert(string_equal_str_p( y, "!")); + assert(string_equal_str_p( z, "!")); + list_string_get_str(y, x, false); + assert(string_equal_str_p(y, "[\"Hello\",\"2 World\",\"!\"]")); + list_string_get_str(y, xx, false); + assert(string_equal_str_p(y, "[\"Hello\",\"2 World\",\"!\"]")); + list_string_get_str(y, zz, false); + assert(string_equal_str_p(y, "[\"Hellno\"]")); + list_string_get_str(y, zx, false); + assert(string_equal_str_p(y, "[\"!\"]")); + list_string_get_str(y, tab_name, false); + assert(string_equal_str_p(y, "[\"My\",\"CD\",\"IS\",\"OUT\"]")); + } +} + int main(void) { test_uint(); @@ -682,6 +709,7 @@ int main(void) test_dual_it1(); test_out_default_oplist(); test_double(); + test_let_string(); exit(0); }