[PATCH 06/12] util/string-map: add round trip test

Subject: [PATCH 06/12] util/string-map: add round trip test

Date: Fri, 22 Jun 2018 22:42:41 -0300

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


In particular this tests that we are not escaping more than necessary.
---
 test/T710-string-map.sh | 58 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/test/T710-string-map.sh b/test/T710-string-map.sh
index 9c5c1d8e..8fd69a53 100755
--- a/test/T710-string-map.sh
+++ b/test/T710-string-map.sh
@@ -426,4 +426,62 @@ val[3]=testval4
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "Round trip from string"
+cat c_head - c_tail <<'EOF' | test_C $
+{
+    const char * str =
+         "testkey1\n"
+         "testval1\\b\n"
+         "testkey1\n"
+         "testval3\\\n"
+         "testkey1\\nkey continues\n"
+         "testval3\\nvalue continues\n"
+         "testkey2\n"
+         "testval2\n"
+         "testkey2\\\\not\n"
+         "testval2\n"
+         "testkey2\\toto\n"
+         "testval4\n";
+
+
+    notmuch_string_map_t *map = _notmuch_string_map_deserialize (ctx, str);
+    const char * str2 = _notmuch_string_map_serialize (ctx, map);
+    fputs (str, stdout);
+    fputs ("--------------------------------------------------\n", stdout);
+    fputs (str2, stdout);
+    printf ("%d\n", strcmp (str, str2));
+}
+EOF
+cat<<'EOF' > EXPECTED
+== stdout ==
+testkey1
+testval1\b
+testkey1
+testval3\
+testkey1\nkey continues
+testval3\nvalue continues
+testkey2
+testval2
+testkey2\\not
+testval2
+testkey2\toto
+testval4
+--------------------------------------------------
+testkey1
+testval1\b
+testkey1
+testval3\
+testkey1\nkey continues
+testval3\nvalue continues
+testkey2
+testval2
+testkey2\\not
+testval2
+testkey2\toto
+testval4
+0
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.17.1

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: