@@ -27,7 +27,6 @@ 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=) | |||
@@ -19,6 +19,7 @@ static struct { | |||
{ "plain", JSON_C_TO_STRING_PLAIN }, | |||
{ "spaced", JSON_C_TO_STRING_SPACED }, | |||
{ "pretty", JSON_C_TO_STRING_PRETTY }, | |||
{ "pretty_tab", JSON_C_TO_STRING_PRETTY_TAB }, | |||
}; | |||
#ifndef NELEM | |||
@@ -19,4 +19,20 @@ for flag in plain spaced pretty ; do | |||
fi | |||
done | |||
# Spaced and pretty JSON string | |||
run_output_test -o test1Formatted_spaced_pretty \ | |||
test1Formatted spaced pretty | |||
_err2=$? | |||
if [ $_err -eq 0 ] ; then | |||
_err=$_err2 | |||
fi | |||
# Spaced and pretty JSON string using tabs | |||
run_output_test -o test1Formatted_spaced_pretty_pretty_tab \ | |||
test1Formatted spaced pretty pretty_tab | |||
_err2=$? | |||
if [ $_err -eq 0 ] ; then | |||
_err=$_err2 | |||
fi | |||
exit $_err |
@@ -0,0 +1,86 @@ | |||
my_string= | |||
my_string.to_string()="\t" | |||
my_string=\ | |||
my_string.to_string()="\\" | |||
my_string=/ | |||
my_string.to_string()="\/" | |||
my_string.to_string(NOSLASHESCAPE)="/" | |||
my_string=/foo/bar/baz | |||
my_string.to_string()="\/foo\/bar\/baz" | |||
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz" | |||
my_string=foo | |||
my_string.to_string()="foo" | |||
my_int=9 | |||
my_int.to_string()=9 | |||
my_array= | |||
[0]=1 | |||
[1]=2 | |||
[2]=3 | |||
[3]=null | |||
[4]=5 | |||
my_array.to_string()=[ | |||
1, | |||
2, | |||
3, | |||
null, | |||
5 | |||
] | |||
my_array= | |||
[0]=1 | |||
[1]=2 | |||
[2]=3 | |||
[3]=4 | |||
[4]=5 | |||
[5]=null | |||
[6]=7 | |||
my_array.to_string()=[1,2,3,4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[7] | |||
after del_idx(0,1)=0, my_array.to_string()=[] | |||
after del_idx(0,1)=-1, my_array.to_string()=[] | |||
after del_idx(0,7)=0, my_array.to_string()=[] | |||
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] | |||
after del_idx(0,6)=0, my_array.to_string()=[7] | |||
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] | |||
my_array= | |||
[0]=3 | |||
[1]=1 | |||
[2]=2 | |||
[3]=null | |||
[4]=0 | |||
my_array.to_string()=[ | |||
3, | |||
1, | |||
2, | |||
null, | |||
0 | |||
] | |||
my_array= | |||
[0]=null | |||
[1]=0 | |||
[2]=1 | |||
[3]=2 | |||
[4]=3 | |||
my_array.to_string()=[ | |||
null, | |||
0, | |||
1, | |||
2, | |||
3 | |||
] | |||
baz_obj.to_string()="fark" | |||
my_object= | |||
abc: 12 | |||
foo: "bar" | |||
bool0: false | |||
bool1: true | |||
my_object.to_string()={ | |||
"abc": 12, | |||
"foo": "bar", | |||
"bool0": false, | |||
"bool1": true | |||
} |
@@ -0,0 +1,86 @@ | |||
my_string= | |||
my_string.to_string()="\t" | |||
my_string=\ | |||
my_string.to_string()="\\" | |||
my_string=/ | |||
my_string.to_string()="\/" | |||
my_string.to_string(NOSLASHESCAPE)="/" | |||
my_string=/foo/bar/baz | |||
my_string.to_string()="\/foo\/bar\/baz" | |||
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz" | |||
my_string=foo | |||
my_string.to_string()="foo" | |||
my_int=9 | |||
my_int.to_string()=9 | |||
my_array= | |||
[0]=1 | |||
[1]=2 | |||
[2]=3 | |||
[3]=null | |||
[4]=5 | |||
my_array.to_string()=[ | |||
1, | |||
2, | |||
3, | |||
null, | |||
5 | |||
] | |||
my_array= | |||
[0]=1 | |||
[1]=2 | |||
[2]=3 | |||
[3]=4 | |||
[4]=5 | |||
[5]=null | |||
[6]=7 | |||
my_array.to_string()=[1,2,3,4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[5,null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[null,7] | |||
after del_idx(0,1)=0, my_array.to_string()=[7] | |||
after del_idx(0,1)=0, my_array.to_string()=[] | |||
after del_idx(0,1)=-1, my_array.to_string()=[] | |||
after del_idx(0,7)=0, my_array.to_string()=[] | |||
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7] | |||
after del_idx(0,6)=0, my_array.to_string()=[7] | |||
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"] | |||
my_array= | |||
[0]=3 | |||
[1]=1 | |||
[2]=2 | |||
[3]=null | |||
[4]=0 | |||
my_array.to_string()=[ | |||
3, | |||
1, | |||
2, | |||
null, | |||
0 | |||
] | |||
my_array= | |||
[0]=null | |||
[1]=0 | |||
[2]=1 | |||
[3]=2 | |||
[4]=3 | |||
my_array.to_string()=[ | |||
null, | |||
0, | |||
1, | |||
2, | |||
3 | |||
] | |||
baz_obj.to_string()="fark" | |||
my_object= | |||
abc: 12 | |||
foo: "bar" | |||
bool0: false | |||
bool1: true | |||
my_object.to_string()={ | |||
"abc": 12, | |||
"foo": "bar", | |||
"bool0": false, | |||
"bool1": true | |||
} |
@@ -19,4 +19,20 @@ for flag in plain spaced pretty ; do | |||
fi | |||
done | |||
# Spaced and pretty JSON string | |||
run_output_test -o test2Formatted_spaced_pretty \ | |||
test2Formatted spaced pretty | |||
_err2=$? | |||
if [ $_err -eq 0 ] ; then | |||
_err=$_err2 | |||
fi | |||
# Spaced and pretty JSON string using tabs | |||
run_output_test -o test2Formatted_spaced_pretty_pretty_tab \ | |||
test2Formatted spaced pretty pretty_tab | |||
_err2=$? | |||
if [ $_err -eq 0 ] ; then | |||
_err=$_err2 | |||
fi | |||
exit $_err |
@@ -0,0 +1,23 @@ | |||
new_obj.to_string()={ | |||
"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" | |||
] | |||
} | |||
] | |||
} | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
new_obj.to_string()={ | |||
"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" | |||
] | |||
} | |||
] | |||
} | |||
} | |||
} |
@@ -1,34 +0,0 @@ | |||
#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; | |||
} |
@@ -1,55 +0,0 @@ | |||
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" | |||
] | |||
} | |||
] | |||
} | |||
} | |||
} |
@@ -1 +0,0 @@ | |||
test_basic.test |