]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Added a test for the space after \n issue with flags=JSON_C_TO_STRING_SPACED|JSON_C_T...
authorDarjan Krijan <darjan_krijan@gmx.de>
Wed, 21 Nov 2018 21:41:13 +0000 (22:41 +0100)
committerDarjan Krijan <darjan_krijan@gmx.de>
Wed, 21 Nov 2018 21:41:13 +0000 (22:41 +0100)
tests/Makefile.am
tests/test_string_spaced_pretty.c [new file with mode: 0644]
tests/test_string_spaced_pretty.expected [new file with mode: 0644]
tests/test_string_spaced_pretty.test [new symlink]

index ea57bdab6e0427b9f77bd606ce30f6d5b05cfa8c..80ae468e063385195ce5bf9486bdf0d05d48175a 100644 (file)
@@ -27,6 +27,7 @@ TESTS+= test_set_value.test
 TESTS+= test_visit.test
 TESTS+= test_json_pointer.test
 TESTS+= test_int_add.test
+TESTS+= test_string_spaced_pretty.test
 
 check_PROGRAMS=
 check_PROGRAMS += $(TESTS:.test=)
diff --git a/tests/test_string_spaced_pretty.c b/tests/test_string_spaced_pretty.c
new file mode 100644 (file)
index 0000000..59da6a7
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <assert.h>
+
+#include "json.h"
+
+int main(int argc, char **argv)
+{
+       json_object *j;
+
+       j = json_tokener_parse("/* more difficult test case */"
+                                    "{ \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to create markup languages such as DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }");
+
+       printf("flags = 0:\n%s\n\n",
+                       json_object_to_json_string_ext(j, 0));
+
+       printf("flags = JSON_C_TO_STRING_SPACED:\n%s\n\n",
+                       json_object_to_json_string_ext(j, JSON_C_TO_STRING_SPACED));
+
+       printf("flags = JSON_C_TO_STRING_SPACED|JSON_C_TO_STRING_PRETTY:\n%s\n\n",
+                       json_object_to_json_string_ext(j, JSON_C_TO_STRING_SPACED
+                                                                                               |JSON_C_TO_STRING_PRETTY));
+
+       printf("flags = JSON_C_TO_STRING_SPACED|JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_PRETTY_TAB:\n%s\n",
+                       json_object_to_json_string_ext(j, JSON_C_TO_STRING_SPACED
+                                                                                               |JSON_C_TO_STRING_PRETTY
+                                                                                               |JSON_C_TO_STRING_PRETTY_TAB));
+
+       json_object_put(j);
+
+       return EXIT_SUCCESS;
+}
diff --git a/tests/test_string_spaced_pretty.expected b/tests/test_string_spaced_pretty.expected
new file mode 100644 (file)
index 0000000..193002e
--- /dev/null
@@ -0,0 +1,55 @@
+flags = 0:
+{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":[{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML","markup"]}]}}}
+
+flags = JSON_C_TO_STRING_SPACED:
+{ "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": [ { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": [ "GML", "XML", "markup" ] } ] } } }
+
+flags = JSON_C_TO_STRING_SPACED|JSON_C_TO_STRING_PRETTY:
+{
+  "glossary": {
+    "title": "example glossary",
+    "GlossDiv": {
+      "title": "S",
+      "GlossList": [
+        {
+          "ID": "SGML",
+          "SortAs": "SGML",
+          "GlossTerm": "Standard Generalized Markup Language",
+          "Acronym": "SGML",
+          "Abbrev": "ISO 8879:1986",
+          "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.",
+          "GlossSeeAlso": [
+            "GML",
+            "XML",
+            "markup"
+          ]
+        }
+      ]
+    }
+  }
+}
+
+flags = JSON_C_TO_STRING_SPACED|JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_PRETTY_TAB:
+{
+       "glossary": {
+               "title": "example glossary",
+               "GlossDiv": {
+                       "title": "S",
+                       "GlossList": [
+                               {
+                                       "ID": "SGML",
+                                       "SortAs": "SGML",
+                                       "GlossTerm": "Standard Generalized Markup Language",
+                                       "Acronym": "SGML",
+                                       "Abbrev": "ISO 8879:1986",
+                                       "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.",
+                                       "GlossSeeAlso": [
+                                               "GML",
+                                               "XML",
+                                               "markup"
+                                       ]
+                               }
+                       ]
+               }
+       }
+}
diff --git a/tests/test_string_spaced_pretty.test b/tests/test_string_spaced_pretty.test
new file mode 120000 (symlink)
index 0000000..58a13f4
--- /dev/null
@@ -0,0 +1 @@
+test_basic.test
\ No newline at end of file