Code

data: Support array + element concatenation.
[sysdb.git] / t / unit / core / data_test.c
index 704ebdd48b43ae58cf38b62c8d18fb4c0e1b781c..2baa6a15876d05ff53b1b98283379cf7d1f50f1a 100644 (file)
@@ -911,8 +911,12 @@ START_TEST(test_expr_eval)
        sdb_data_t err = { -1, { .integer = 0 } };
 
        int64_t int_values[] = { 47, 11, 23 };
+       int64_t expected_int_append[] = { 47, 11, 23, 42 };
+       int64_t expected_int_prepend[] = { 42, 47, 11, 23 };
        int64_t expected_int_concat[] = { 47, 11, 23, 47, 11, 23 };
        char *string_values[] = { "foo", "bar", "qux" "baz" };
+       char *expected_string_append[] = { "foo", "bar", "qux" "baz", "bay" };
+       char *expected_string_prepend[] = { "bay", "foo", "bar", "qux" "baz" };
        char *expected_string_concat[] =
                { "foo", "bar", "qux" "baz", "foo", "bar", "qux" "baz" };
 
@@ -1077,6 +1081,44 @@ START_TEST(test_expr_eval)
                                } },
                        },
                },
+               {
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_INTEGER,
+                               { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } },
+                       },
+                       { SDB_TYPE_INTEGER, { .integer = 42 }, },
+                       err,
+                       err,
+                       err,
+                       err,
+                       err,
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_INTEGER,
+                               { .array = {
+                                               SDB_STATIC_ARRAY_LEN(expected_int_append),
+                                               expected_int_append
+                               } },
+                       },
+               },
+               {
+                       { SDB_TYPE_INTEGER, { .integer = 42 }, },
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_INTEGER,
+                               { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } },
+                       },
+                       err,
+                       err,
+                       err,
+                       err,
+                       err,
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_INTEGER,
+                               { .array = {
+                                               SDB_STATIC_ARRAY_LEN(expected_int_prepend),
+                                               expected_int_prepend
+                               } },
+                       },
+               },
                {
                        {
                                SDB_TYPE_ARRAY | SDB_TYPE_STRING,
@@ -1099,6 +1141,44 @@ START_TEST(test_expr_eval)
                                } },
                        },
                },
+               {
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_STRING,
+                               { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } },
+                       },
+                       { SDB_TYPE_STRING, { .string = "bay" } },
+                       err,
+                       err,
+                       err,
+                       err,
+                       err,
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_STRING,
+                               { .array = {
+                                               SDB_STATIC_ARRAY_LEN(expected_string_append),
+                                               expected_string_append
+                               } },
+                       },
+               },
+               {
+                       { SDB_TYPE_STRING, { .string = "bay" } },
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_STRING,
+                               { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } },
+                       },
+                       err,
+                       err,
+                       err,
+                       err,
+                       err,
+                       {
+                               SDB_TYPE_ARRAY | SDB_TYPE_STRING,
+                               { .array = {
+                                               SDB_STATIC_ARRAY_LEN(expected_string_prepend),
+                                               expected_string_prepend
+                               } },
+                       },
+               },
                {
                        { SDB_TYPE_NULL, { .integer = 0 } },
                        { SDB_TYPE_NULL, { .integer = 0 } },
@@ -1591,6 +1671,9 @@ END_TEST
 
 START_TEST(test_format)
 {
+       int64_t int_values[] = { 47, 11, 23 };
+       char *string_values[] = { "foo", "bar", "qux", "baz" };
+
        struct {
                sdb_data_t datum;
                const char *expected;
@@ -1638,6 +1721,20 @@ START_TEST(test_format)
                        { SDB_TYPE_REGEX, { .re = { "some regex", empty_re } } },
                        "\"/some regex/\"",
                },
+               {
+                       {
+                               SDB_TYPE_INTEGER | SDB_TYPE_ARRAY,
+                               { .array = { SDB_STATIC_ARRAY_LEN(int_values), int_values } },
+                       },
+                       "[47, 11, 23]",
+               },
+               {
+                       {
+                               SDB_TYPE_STRING | SDB_TYPE_ARRAY,
+                               { .array = { SDB_STATIC_ARRAY_LEN(string_values), string_values } },
+                       },
+                       "[\"foo\", \"bar\", \"qux\", \"baz\"]",
+               },
        };
 
        size_t i;