diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-01-01 03:41:41 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-01-01 03:41:41 +0100 |
commit | 2442ee791e0ab49e1897b45191e021b81dd8be3b (patch) | |
tree | 836ee111058e7680b523281e33c533da099bac45 /tests/common/check_config_parser.c | |
parent | 30a54138d73341d1be861d03b3532ea094332a86 (diff) | |
download | blogc-2442ee791e0ab49e1897b45191e021b81dd8be3b.tar.gz blogc-2442ee791e0ab49e1897b45191e021b81dd8be3b.tar.bz2 blogc-2442ee791e0ab49e1897b45191e021b81dd8be3b.zip |
config-parser: allow quoted values
Diffstat (limited to 'tests/common/check_config_parser.c')
-rw-r--r-- | tests/common/check_config_parser.c | 115 |
1 files changed, 111 insertions, 4 deletions
diff --git a/tests/common/check_config_parser.c b/tests/common/check_config_parser.c index a04dc6d..7c3cb4a 100644 --- a/tests/common/check_config_parser.c +++ b/tests/common/check_config_parser.c @@ -142,7 +142,7 @@ test_config_section_multiple_keys(void **state) const char *a = "[foo]\n" "asd = zxc\n" - "qwe = rty\n" + "qwe = rty \n" "zxc = vbn"; bc_error_t *err = NULL; bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err); @@ -172,7 +172,7 @@ test_config_section_multiple_keys(void **state) a = "[foo]\n" "asd = zxc\n" - "qwe = rty\n" + "qwe = rty \n" "zxc = vbn\n"; err = NULL; c = bc_config_parse(a, strlen(a), NULL, &err); @@ -202,7 +202,7 @@ test_config_section_multiple_keys(void **state) a = "[foo]\r\n" "asd = zxc\r\n" - "qwe = rty\r\n" + "qwe = rty \r\n" "zxc = vbn\r\n"; err = NULL; c = bc_config_parse(a, strlen(a), NULL, &err); @@ -370,7 +370,7 @@ test_config_section_list(void **state) "\n" "[bar]\n" "lol = hehe\n" - "asdasdadssad"; + " asdasdadssad "; bc_error_t *err = NULL; const char *sections[] = {"bar", NULL}; bc_config_t *c = bc_config_parse(a, strlen(a), sections, &err); @@ -495,6 +495,112 @@ test_config_section_list(void **state) static void +test_config_quoted_values(void **state) +{ + const char *a = + "[foo]\n" + "a = \"lol\"\n" + "b = \"lo\\\"l\"\n" + "c = \"lo'l\"\n" + "d = 'lol'\n" + "e = 'lo\\'l'\n" + "f = 'lo\"l'\n" + "g = \\\\asd\n" + "h = \"\\\\asd\"\n" + "i = '\\\\asd'\n"; + bc_error_t *err = NULL; + bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err); + assert_null(err); + assert_non_null(c); + assert_non_null(c->root); + assert_int_equal(bc_trie_size(c->root), 1); + char **s = bc_config_list_sections(c); + assert_non_null(s); + assert_int_equal(bc_strv_length(s), 1); + assert_string_equal(s[0], "foo"); + assert_null(s[1]); + bc_strv_free(s); + char **k = bc_config_list_keys(c, "foo"); + assert_non_null(k); + assert_int_equal(bc_strv_length(k), 9); + assert_string_equal(k[0], "a"); + assert_string_equal(k[1], "b"); + assert_string_equal(k[2], "c"); + assert_string_equal(k[3], "d"); + assert_string_equal(k[4], "e"); + assert_string_equal(k[5], "f"); + assert_string_equal(k[6], "g"); + assert_string_equal(k[7], "h"); + assert_string_equal(k[8], "i"); + assert_null(k[9]); + bc_strv_free(k); + assert_string_equal(bc_config_get(c, "foo", "a"), "lol"); + assert_string_equal(bc_config_get(c, "foo", "b"), "lo\"l"); + assert_string_equal(bc_config_get(c, "foo", "c"), "lo'l"); + assert_string_equal(bc_config_get(c, "foo", "d"), "lol"); + assert_string_equal(bc_config_get(c, "foo", "e"), "lo'l"); + assert_string_equal(bc_config_get(c, "foo", "f"), "lo\"l"); + assert_string_equal(bc_config_get(c, "foo", "g"), "\\asd"); + assert_string_equal(bc_config_get(c, "foo", "h"), "\\asd"); + assert_string_equal(bc_config_get(c, "foo", "i"), "\\asd"); + bc_config_free(c); + + a = + "[foo]\n" + "\"lol\"\n" + "\"lo\\\"l\"\n" + "\"lo'l\"\n" + "'lol'\n" + "'lo\\'l'\n" + "'lo\"l'\n" + "\\\\asd\n" + "\"\\\\asd\"\n" + "'\\\\asd'\n" + "\n" + "[bar]\n" + "'lol = hehe'\n" + "\" asdasdadssad \""; + err = NULL; + const char *sections[] = {"foo", "bar", NULL}; + c = bc_config_parse(a, strlen(a), sections, &err); + assert_null(err); + assert_non_null(c); + assert_non_null(c->root); + assert_int_equal(bc_trie_size(c->root), 2); + s = bc_config_list_sections(c); + assert_non_null(s); + assert_int_equal(bc_strv_length(s), 2); + assert_string_equal(s[0], "foo"); + assert_string_equal(s[1], "bar"); + assert_null(s[2]); + bc_strv_free(s); + char **bar = bc_config_get_list(c, "foo"); + assert_string_equal(bar[0], "lol"); + assert_string_equal(bar[1], "lo\"l"); + assert_string_equal(bar[2], "lo'l"); + assert_string_equal(bar[3], "lol"); + assert_string_equal(bar[4], "lo'l"); + assert_string_equal(bar[5], "lo\"l"); + assert_string_equal(bar[6], "\\asd"); + assert_string_equal(bar[7], "\\asd"); + assert_string_equal(bar[8], "\\asd"); + assert_null(bar[9]); + bc_strv_free(bar); + bar = bc_config_get_list(c, "bar"); + assert_non_null(bar); + assert_string_equal(bar[0], "lol = hehe"); + assert_string_equal(bar[1], " asdasdadssad "); + assert_null(bar[2]); + bc_strv_free(bar); + k = bc_config_list_keys(c, "foo"); + assert_null(k); + k = bc_config_list_keys(c, "bar"); + assert_null(k); + bc_config_free(c); +} + + +static void test_config_error_start(void **state) { const char *a = @@ -571,6 +677,7 @@ main(void) unit_test(test_config_section_multiple_keys), unit_test(test_config_section_multiple_sections), unit_test(test_config_section_list), + unit_test(test_config_quoted_values), unit_test(test_config_error_start), unit_test(test_config_error_section_with_newline), unit_test(test_config_error_key_without_value), |