neatjson 0.6.2 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +199 -194
- data/lib/neatjson.rb +24 -23
- data/neatjson.gemspec +17 -17
- data/test/test_neatjson.rb +0 -0
- data/test/tests.js +173 -167
- data/test/tests.rb +169 -165
- metadata +3 -3
data/neatjson.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'date'
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "neatjson"
|
5
|
-
s.version = "0.
|
6
|
-
s.date = Date.today.iso8601
|
7
|
-
s.authors = ["Gavin Kistner"]
|
8
|
-
s.email = "gavin@phrogz.net"
|
9
|
-
s.homepage = "http://github.com/Phrogz/NeatJSON"
|
10
|
-
s.summary = "Pretty, powerful, flexible JSON generation."
|
11
|
-
s.description = "Generate JSON strings from Ruby objects with flexible formatting options. Key features: keep arrays and objects on a single line when they fit; format floats to specific precision; sort and align object keys; adjust whitespace padding of arrays and objects, inside and around commas and colons. JavaScript version included."
|
12
|
-
s.license = "MIT license (MIT)"
|
13
|
-
s.platform = Gem::Platform::RUBY
|
14
|
-
s.require_paths = ['lib']
|
15
|
-
s.files = Dir.glob("{lib,test,html}/**/*") + ['LICENSE.txt', 'README.md', '.yardopts', __FILE__]
|
16
|
-
s.has_rdoc = 'yard'
|
17
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'date'
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "neatjson"
|
5
|
+
s.version = "0.7"
|
6
|
+
s.date = Date.today.iso8601
|
7
|
+
s.authors = ["Gavin Kistner"]
|
8
|
+
s.email = "gavin@phrogz.net"
|
9
|
+
s.homepage = "http://github.com/Phrogz/NeatJSON"
|
10
|
+
s.summary = "Pretty, powerful, flexible JSON generation."
|
11
|
+
s.description = "Generate JSON strings from Ruby objects with flexible formatting options. Key features: keep arrays and objects on a single line when they fit; format floats to specific precision; sort and align object keys; adjust whitespace padding of arrays and objects, inside and around commas and colons. JavaScript version included."
|
12
|
+
s.license = "MIT license (MIT)"
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
s.files = Dir.glob("{lib,test,html}/**/*") + ['LICENSE.txt', 'README.md', '.yardopts', __FILE__]
|
16
|
+
s.has_rdoc = 'yard'
|
17
|
+
end
|
data/test/test_neatjson.rb
CHANGED
File without changes
|
data/test/tests.js
CHANGED
@@ -1,167 +1,173 @@
|
|
1
|
-
exports.tests = [
|
2
|
-
{value:true, tests:[{json:"true" }]},
|
3
|
-
{value:false, tests:[{json:"false" }]},
|
4
|
-
// {value:nil, tests:[{json:"null" }]},
|
5
|
-
{value:null, tests:[{json:"null" }]},
|
6
|
-
{value:undefined,tests:[{json:"null" }]},
|
7
|
-
{value:5, tests:[
|
8
|
-
{json:"5"},
|
9
|
-
{json:"5", opts:{decimals:3}}
|
10
|
-
]},
|
11
|
-
{value:5.0, tests:[
|
12
|
-
{json:"5"},
|
13
|
-
{json:"5", opts:{decimals:3}}
|
14
|
-
]},
|
15
|
-
{value:5.0001, tests:[
|
16
|
-
{json:"5.0001"},
|
17
|
-
{json:"5.000", opts:{decimals:3}}
|
18
|
-
]},
|
19
|
-
{value:4.2, tests:[
|
20
|
-
{json:"4.2"},
|
21
|
-
{json:"4", opts:{decimals:0}},
|
22
|
-
{json:"4.20",opts:{decimals:2}},
|
23
|
-
]},
|
24
|
-
{value:4.199, tests:[{json:"4.20", opts:{decimals:2}}]},
|
25
|
-
{value:4.204, tests:[{json:"4.20", opts:{decimals:2}}]},
|
26
|
-
{value:-1.9, tests:[{json:"-2", opts:{decimals:0}}]},
|
27
|
-
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
28
|
-
{value:1e23, tests:[{json:/1(?:\.0+)?e\+23/i}]},
|
29
|
-
{value:1e-9, tests:[{json:/1(?:\.0+)?e-0*9/i}]},
|
30
|
-
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
31
|
-
|
32
|
-
{value:"foo", tests:[{json:"\"foo\""}]},
|
33
|
-
// {value: :foo, tests:[{json:"\"foo\""}]},
|
34
|
-
{value:"foo\nbar", tests:[{json:"\"foo\\nbar\""}]},
|
35
|
-
|
36
|
-
{value:[1,2,3,4,[5,6,7,[8,9,10],11,12]], tests:[
|
37
|
-
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
|
38
|
-
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [5,6,7,[8,9,10],11,12]\n]", opts:{wrap:30} },
|
39
|
-
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [8,9,10],\n 11,\n 12\n ]\n]", opts:{wrap:20} },
|
40
|
-
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [\n 8,\n 9,\n 10\n ],\n 11,\n 12\n ]\n]", opts:{wrap:true} },
|
41
|
-
{ json:"[\n\t1,\n\t2,\n\t3,\n\t4,\n\t[\n\t\t5,\n\t\t6,\n\t\t7,\n\t\t[\n\t\t\t8,\n\t\t\t9,\n\t\t\t10\n\t\t],\n\t\t11,\n\t\t12\n\t]\n]", opts:{wrap:true,indent:"\t"} },
|
42
|
-
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]", opts:{arrayPadding:0} },
|
43
|
-
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{arrayPadding:1} },
|
44
|
-
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{arrayPadding:2} },
|
45
|
-
{ json:"[1, 2, 3, 4, [5, 6, 7, [8, 9, 10], 11, 12]]", opts:{afterComma:1} },
|
46
|
-
{ json:"[ 1, 2, 3, 4, [ 5, 6, 7, [ 8, 9, 10 ], 11, 12 ] ]", opts:{afterComma:1,arrayPadding:1} },
|
47
|
-
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true} },
|
48
|
-
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true,afterComma:1} },
|
49
|
-
{ json:"[ 1,\n 2,\n 3,\n 4,\n [ 5,\n 6,\n 7,\n [ 8,\n 9,\n 10 ],\n 11,\n 12 ] ]", opts:{short:true,wrap:true,arrayPadding:1} },
|
50
|
-
]},
|
51
|
-
|
52
|
-
{value:[1,2,3], tests:[
|
53
|
-
{ json:"[1,2,3]" },
|
54
|
-
{ json:"[1 ,2 ,3]", opts:{beforeComma:1} },
|
55
|
-
{ json:"[1 , 2 , 3]", opts:{aroundComma:1} }
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
{ json:'{"
|
62
|
-
{ json:'{"a"
|
63
|
-
{ json:'{"a":
|
64
|
-
{ json:'{"a" :
|
65
|
-
{ json:'{"a"
|
66
|
-
{ json:'{
|
67
|
-
{ json:'{
|
68
|
-
{ json:'{"a" : 2, "b" : 1}',
|
69
|
-
{ json:'{
|
70
|
-
{ json:'{
|
71
|
-
{ json:'{"
|
72
|
-
{ json:'{"
|
73
|
-
{ json:
|
74
|
-
{ json:
|
75
|
-
{ json:"{\n \"b\":
|
76
|
-
{ json:"{\"b\":1,\n
|
77
|
-
{ json:"{\"b\": 1,\n
|
78
|
-
{ json:"{\"b\":
|
79
|
-
{ json:"{\"b\":1,\n \"a\":2}",
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
{ json:"{\"b\":1,\"aaa\":2,\"cc\":3}",
|
86
|
-
{ json:"{\n \"
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
{ json:"{\"a\":
|
96
|
-
]},
|
97
|
-
|
98
|
-
{value:
|
99
|
-
{ json:
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
{ json:
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
{ json:"[1,\n
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
{ json:"{\
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
{ json:"{\"
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
]},
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
{ json:'{"
|
132
|
-
{ json:'{
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
{ json:'
|
138
|
-
{ json:'
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
{ json:'["foo",\n
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
{ json:"
|
154
|
-
]}
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
// {value:Class.new{ def to_json(*a);
|
163
|
-
// { json:'{"a":1}' },
|
164
|
-
// { json:
|
165
|
-
//
|
166
|
-
]
|
167
|
-
|
1
|
+
exports.tests = [
|
2
|
+
{value:true, tests:[{json:"true" }]},
|
3
|
+
{value:false, tests:[{json:"false" }]},
|
4
|
+
// {value:nil, tests:[{json:"null" }]},
|
5
|
+
{value:null, tests:[{json:"null" }]},
|
6
|
+
{value:undefined,tests:[{json:"null" }]},
|
7
|
+
{value:5, tests:[
|
8
|
+
{json:"5"},
|
9
|
+
{json:"5", opts:{decimals:3}},
|
10
|
+
]},
|
11
|
+
{value:5.0, tests:[
|
12
|
+
{json:"5"},
|
13
|
+
{json:"5", opts:{decimals:3}},
|
14
|
+
]},
|
15
|
+
{value:5.0001, tests:[
|
16
|
+
{json:"5.0001"},
|
17
|
+
{json:"5.000", opts:{decimals:3}},
|
18
|
+
]},
|
19
|
+
{value:4.2, tests:[
|
20
|
+
{json:"4.2"},
|
21
|
+
{json:"4", opts:{decimals:0}},
|
22
|
+
{json:"4.20",opts:{decimals:2}},
|
23
|
+
]},
|
24
|
+
{value:4.199, tests:[{json:"4.20", opts:{decimals:2}}]},
|
25
|
+
{value:4.204, tests:[{json:"4.20", opts:{decimals:2}}]},
|
26
|
+
{value:-1.9, tests:[{json:"-2", opts:{decimals:0}}]},
|
27
|
+
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
28
|
+
{value:1e23, tests:[{json:/1(?:\.0+)?e\+23/i}]},
|
29
|
+
{value:1e-9, tests:[{json:/1(?:\.0+)?e-0*9/i}]},
|
30
|
+
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
31
|
+
|
32
|
+
{value:"foo", tests:[{json:"\"foo\""}]},
|
33
|
+
// {value: :foo, tests:[{json:"\"foo\""}]},
|
34
|
+
{value:"foo\nbar", tests:[{json:"\"foo\\nbar\""}]},
|
35
|
+
|
36
|
+
{value:[1,2,3,4,[5,6,7,[8,9,10],11,12]], tests:[
|
37
|
+
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
|
38
|
+
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [5,6,7,[8,9,10],11,12]\n]", opts:{wrap:30} },
|
39
|
+
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [8,9,10],\n 11,\n 12\n ]\n]", opts:{wrap:20} },
|
40
|
+
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [\n 8,\n 9,\n 10\n ],\n 11,\n 12\n ]\n]", opts:{wrap:true} },
|
41
|
+
{ json:"[\n\t1,\n\t2,\n\t3,\n\t4,\n\t[\n\t\t5,\n\t\t6,\n\t\t7,\n\t\t[\n\t\t\t8,\n\t\t\t9,\n\t\t\t10\n\t\t],\n\t\t11,\n\t\t12\n\t]\n]", opts:{wrap:true,indent:"\t"} },
|
42
|
+
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]", opts:{arrayPadding:0} },
|
43
|
+
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{arrayPadding:1} },
|
44
|
+
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{arrayPadding:2} },
|
45
|
+
{ json:"[1, 2, 3, 4, [5, 6, 7, [8, 9, 10], 11, 12]]", opts:{afterComma:1} },
|
46
|
+
{ json:"[ 1, 2, 3, 4, [ 5, 6, 7, [ 8, 9, 10 ], 11, 12 ] ]", opts:{afterComma:1,arrayPadding:1} },
|
47
|
+
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true} },
|
48
|
+
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true,afterComma:1} },
|
49
|
+
{ json:"[ 1,\n 2,\n 3,\n 4,\n [ 5,\n 6,\n 7,\n [ 8,\n 9,\n 10 ],\n 11,\n 12 ] ]", opts:{short:true,wrap:true,arrayPadding:1} },
|
50
|
+
]},
|
51
|
+
|
52
|
+
{value:[1,2,3], tests:[
|
53
|
+
{ json:"[1,2,3]" },
|
54
|
+
{ json:"[1 ,2 ,3]", opts:{beforeComma:1} },
|
55
|
+
{ json:"[1 , 2 , 3]", opts:{aroundComma:1} },
|
56
|
+
{ json:"[\n\t1,\n\t2,\n\t3\n]", opts:{wrap:true,indent:"\t"} },
|
57
|
+
{ json:"[\n\t1,\n\t2,\n\t3\n\t]", opts:{wrap:true,indent:"\t",indentLast:true} },
|
58
|
+
]},
|
59
|
+
|
60
|
+
{value:{b:1,a:2}, tests:[
|
61
|
+
{ json:'{"b":1,"a":2}' },
|
62
|
+
{ json:'{"a":2,"b":1}', opts:{sorted:true} },
|
63
|
+
{ json:'{"a":2, "b":1}', opts:{sorted:true,afterComma:1} },
|
64
|
+
{ json:'{"a" :2,"b" :1}', opts:{sorted:true,beforeColon:1} },
|
65
|
+
{ json:'{"a": 2,"b": 1}', opts:{sorted:true,afterColon:1} },
|
66
|
+
{ json:'{"a" : 2,"b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1} },
|
67
|
+
{ json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1} },
|
68
|
+
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,padding:1} },
|
69
|
+
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:1,afterComma:1,objectPadding:1} },
|
70
|
+
{ json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,arrayPadding:1} },
|
71
|
+
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:2,afterComma:1,padding:2} },
|
72
|
+
{ json:'{ "a":2, "b":1 }', opts:{sorted:true,afterComma:1,padding:2} },
|
73
|
+
{ json:'{"b": 1,"a": 2}', opts:{afterColon1:2} },
|
74
|
+
{ json:'{"b" : 1,"a" : 2}', opts:{aroundColon1:2} },
|
75
|
+
{ json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,aroundColon1:2} },
|
76
|
+
{ json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColon:1} },
|
77
|
+
{ json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColonN:1} },
|
78
|
+
{ json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
|
79
|
+
{ json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColon:1} },
|
80
|
+
{ json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColonN:1} },
|
81
|
+
{ json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,afterColon1:1} },
|
82
|
+
]},
|
83
|
+
|
84
|
+
{value:{b:1,aaa:2,cc:3}, tests:[
|
85
|
+
{ json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
|
86
|
+
{ json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
|
87
|
+
{ json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
|
88
|
+
{ json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} },
|
89
|
+
]},
|
90
|
+
|
91
|
+
{value:{a:1}, tests:[
|
92
|
+
{ json:'{"a":1}' },
|
93
|
+
{ json:"{\n \"a\":1\n}", opts:{wrap:true} },
|
94
|
+
{ json:"{\n \"a\":1\n }", opts:{wrap:true, indentLast:true} },
|
95
|
+
{ json:"{\n \"a\":1\n }", opts:{wrap:true, indentLast:true, indent:" " } },
|
96
|
+
]},
|
97
|
+
|
98
|
+
{value:{ b:17, a:42 }, tests:[
|
99
|
+
{ json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} },
|
100
|
+
]},
|
101
|
+
|
102
|
+
{value:[1,{a:2},3], tests:[
|
103
|
+
{ json:'[1,{"a":2},3]' },
|
104
|
+
{ json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
|
105
|
+
{ json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,afterComma:1} },
|
106
|
+
{ json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
|
107
|
+
{ json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} },
|
108
|
+
{ json:"[\n 1,\n {\n \"a\":2\n },\n 3\n ]", opts:{wrap:true,indentLast:true} },
|
109
|
+
]},
|
110
|
+
|
111
|
+
{value:[1,{a:2,b:3},4], tests:[
|
112
|
+
{ json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
|
113
|
+
]},
|
114
|
+
|
115
|
+
{value:{a:1,b:[2,3,4],c:3}, tests:[
|
116
|
+
{ json:'{"a":1,"b":[2,3,4],"c":3}' },
|
117
|
+
{ json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
|
118
|
+
{ json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} },
|
119
|
+
{ json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n }", opts:{wrap:true,indentLast:true} },
|
120
|
+
]},
|
121
|
+
|
122
|
+
{value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
|
123
|
+
{ json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} },
|
124
|
+
]},
|
125
|
+
|
126
|
+
{value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
|
127
|
+
{ json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} },
|
128
|
+
]},
|
129
|
+
|
130
|
+
{value:{"abcdefghij":[{"abcdefghijklmnop":{}}]}, tests:[
|
131
|
+
{ json:'{"abcdefghij":[{"abcdefghijklmnop":{}}]}' },
|
132
|
+
{ json:'{"abcdefghij" : [{"abcdefghijklmnop" : {}}]}', opts:{wrap:1, short:true, aroundColonN:1} },
|
133
|
+
]},
|
134
|
+
|
135
|
+
{value:{"foo":{}}, tests:[
|
136
|
+
{ json:'{"foo":{}}' },
|
137
|
+
{ json:'{"foo":{}}', opts:{wrap:false} },
|
138
|
+
{ json:'{\n "foo":{}\n}', opts:{wrap:5} },
|
139
|
+
{ json:'{"foo":{}}', opts:{wrap:1, short:true} },
|
140
|
+
]},
|
141
|
+
|
142
|
+
{value:["foo",{},"bar"], tests:[
|
143
|
+
{ json:'[\n "foo",\n {},\n "bar"\n]', opts:{wrap:1} },
|
144
|
+
{ json:'["foo",\n {},\n "bar"]', opts:{wrap:1, short:true} },
|
145
|
+
]},
|
146
|
+
|
147
|
+
{value:["foo",[],"bar"], tests:[
|
148
|
+
{ json:'[\n "foo",\n [],\n "bar"\n]', opts:{wrap:1} },
|
149
|
+
{ json:'["foo",\n [],\n "bar"]', opts:{wrap:1, short:true} },
|
150
|
+
]},
|
151
|
+
|
152
|
+
{value:["foo",[{},[{"foo":[]},42]],"bar"], tests:[
|
153
|
+
{ json:'["foo",\n [{},\n [{"foo":[]},\n 42]],\n "bar"]', opts:{wrap:1, short:true} },
|
154
|
+
]},
|
155
|
+
|
156
|
+
{value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
|
157
|
+
{ json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
|
158
|
+
{ json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
|
159
|
+
{ json:"{\n \"a\":{\n \"b\":{\n \"c\":{\n \"d\":{\n \"e\":{\n \"f\":{\n \"g\":{\n \"h\":{\n \"i\":{\n \"j\":{\n \"k\":{\n \"l\":{\n \"m\":1\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n}", opts:{wrap:1} },
|
160
|
+
]},
|
161
|
+
|
162
|
+
// {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
|
163
|
+
// { json:'{ "a":1}' },
|
164
|
+
// { json:'{ "a":1}', opts:{wrap:true} },
|
165
|
+
// { json:'{"a":1}', opts:{indent:''} },
|
166
|
+
// ]},
|
167
|
+
|
168
|
+
// {value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
|
169
|
+
// { json:'{"a":1}' },
|
170
|
+
// { json:"{\n \"a\":1\n}", opts:{wrap:true} }
|
171
|
+
// ]}
|
172
|
+
]
|
173
|
+
|
data/test/tests.rb
CHANGED
@@ -1,165 +1,169 @@
|
|
1
|
-
TESTS = [
|
2
|
-
{value:true, tests:[{json:"true" }]},
|
3
|
-
{value:false, tests:[{json:"false" }]},
|
4
|
-
{value:nil, tests:[{json:"null" }]},
|
5
|
-
{value:5, tests:[
|
6
|
-
{json:"5"},
|
7
|
-
{json:"5", opts:{decimals:3}}
|
8
|
-
]},
|
9
|
-
{value:5.0, tests:[
|
10
|
-
{json:"5"},
|
11
|
-
{json:"5", opts:{decimals:3}}
|
12
|
-
]},
|
13
|
-
{value:5.0001, tests:[
|
14
|
-
{json:"5.0001"},
|
15
|
-
{json:"5.000", opts:{decimals:3}}
|
16
|
-
]},
|
17
|
-
{value:4.2, tests:[
|
18
|
-
{json:"4.2"},
|
19
|
-
{json:"4", opts:{decimals:0}},
|
20
|
-
{json:"4.20",opts:{decimals:2}},
|
21
|
-
]},
|
22
|
-
{value:4.199, tests:[{json:"4.20", opts:{decimals:2}}]},
|
23
|
-
{value:4.204, tests:[{json:"4.20", opts:{decimals:2}}]},
|
24
|
-
{value:-1.9, tests:[{json:"-2", opts:{decimals:0}}]},
|
25
|
-
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
26
|
-
{value:1e23, tests:[{json:/1(?:\.0+)?e\+23/i}]},
|
27
|
-
{value:1e-9, tests:[{json:/1(?:\.0+)?e-0*9/i}]},
|
28
|
-
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
29
|
-
|
30
|
-
{value:"foo", tests:[{json:"\"foo\""}]},
|
31
|
-
{value: :foo, tests:[{json:"\"foo\""}]},
|
32
|
-
{value:"foo\nbar", tests:[{json:"\"foo\\nbar\""}]},
|
33
|
-
|
34
|
-
{value:[1,2,3,4,[5,6,7,[8,9,10],11,12]], tests:[
|
35
|
-
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
|
36
|
-
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [5,6,7,[8,9,10],11,12]\n]", opts:{wrap:30} },
|
37
|
-
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [8,9,10],\n 11,\n 12\n ]\n]", opts:{wrap:20} },
|
38
|
-
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [\n 8,\n 9,\n 10\n ],\n 11,\n 12\n ]\n]", opts:{wrap:true} },
|
39
|
-
{ json:"[\n\t1,\n\t2,\n\t3,\n\t4,\n\t[\n\t\t5,\n\t\t6,\n\t\t7,\n\t\t[\n\t\t\t8,\n\t\t\t9,\n\t\t\t10\n\t\t],\n\t\t11,\n\t\t12\n\t]\n]", opts:{wrap:true,indent:"\t"} },
|
40
|
-
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]", opts:{array_padding:0} },
|
41
|
-
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{array_padding:1} },
|
42
|
-
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{array_padding:2} },
|
43
|
-
{ json:"[1, 2, 3, 4, [5, 6, 7, [8, 9, 10], 11, 12]]", opts:{after_comma:1} },
|
44
|
-
{ json:"[ 1, 2, 3, 4, [ 5, 6, 7, [ 8, 9, 10 ], 11, 12 ] ]", opts:{after_comma:1,array_padding:1} },
|
45
|
-
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true} },
|
46
|
-
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true,after_comma:1} },
|
47
|
-
{ json:"[ 1,\n 2,\n 3,\n 4,\n [ 5,\n 6,\n 7,\n [ 8,\n 9,\n 10 ],\n 11,\n 12 ] ]", opts:{short:true,wrap:true,array_padding:1} },
|
48
|
-
]},
|
49
|
-
|
50
|
-
{value:[1,2,3], tests:[
|
51
|
-
{ json:"[1,2,3]" },
|
52
|
-
{ json:"[1 ,2 ,3]", opts:{before_comma:1} },
|
53
|
-
{ json:"[1 , 2 , 3]", opts:{around_comma:1} }
|
54
|
-
]},
|
55
|
-
|
56
|
-
{value:{b:1,a:2}, tests:[
|
57
|
-
{ json:'{"b":1,"a":2}' },
|
58
|
-
{ json:'{"a":2,"b":1}', opts:{sorted:true} },
|
59
|
-
{ json:'{"a":2, "b":1}', opts:{sorted:true,after_comma:1} },
|
60
|
-
{ json:'{"a" :2,"b" :1}', opts:{sorted:true,before_colon:1} },
|
61
|
-
{ json:'{"a": 2,"b": 1}', opts:{sorted:true,after_colon:1} },
|
62
|
-
{ json:'{"a" : 2,"b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1} },
|
63
|
-
{ json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1} },
|
64
|
-
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,padding:1} },
|
65
|
-
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:1,after_comma:1,object_padding:1} },
|
66
|
-
{ json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,array_padding:1} },
|
67
|
-
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:2,after_comma:1,padding:2} },
|
68
|
-
{ json:'{ "a":2, "b":1 }', opts:{sorted:true,after_comma:1,padding:2} },
|
69
|
-
{ json:'{"b": 1,"a": 2}', opts:{after_colon_1:2} },
|
70
|
-
{ json:'{"b" : 1,"a" : 2}', opts:{around_colon_1:2} },
|
71
|
-
{ json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,around_colon_1:2} },
|
72
|
-
{ json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon:1} },
|
73
|
-
{ json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon_n:1} },
|
74
|
-
{ json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
|
75
|
-
{ json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon:1} },
|
76
|
-
{ json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon_n:1} },
|
77
|
-
{ json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,after_colon_1:1} },
|
78
|
-
]},
|
79
|
-
|
80
|
-
{value:{b:1,aaa:2,cc:3}, tests:[
|
81
|
-
{ json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
|
82
|
-
{ json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
|
83
|
-
{ json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
|
84
|
-
{ json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} }
|
85
|
-
]},
|
86
|
-
|
87
|
-
{value:{a:1}, tests:[
|
88
|
-
{ json:'{"a":1}' },
|
89
|
-
{ json:"{\n \"a\":1\n}",
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
{ json:'[
|
100
|
-
{ json:
|
101
|
-
{ json:
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
{ json:"{\"
|
116
|
-
]},
|
117
|
-
|
118
|
-
{value:{
|
119
|
-
{ json:"{\"
|
120
|
-
]},
|
121
|
-
|
122
|
-
{value:{"
|
123
|
-
{ json:"{\"
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
{ json:"{\"
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
{ json:"
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
{ json:"[\
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
{ json:"[\"foo\",\n [
|
146
|
-
]},
|
147
|
-
|
148
|
-
{value:
|
149
|
-
{ json:
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
{ json:'{"a":1}' },
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
{ json:
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
1
|
+
TESTS = [
|
2
|
+
{value:true, tests:[{json:"true" }]},
|
3
|
+
{value:false, tests:[{json:"false" }]},
|
4
|
+
{value:nil, tests:[{json:"null" }]},
|
5
|
+
{value:5, tests:[
|
6
|
+
{json:"5"},
|
7
|
+
{json:"5", opts:{decimals:3}},
|
8
|
+
]},
|
9
|
+
{value:5.0, tests:[
|
10
|
+
{json:"5"},
|
11
|
+
{json:"5", opts:{decimals:3}},
|
12
|
+
]},
|
13
|
+
{value:5.0001, tests:[
|
14
|
+
{json:"5.0001"},
|
15
|
+
{json:"5.000", opts:{decimals:3}},
|
16
|
+
]},
|
17
|
+
{value:4.2, tests:[
|
18
|
+
{json:"4.2"},
|
19
|
+
{json:"4", opts:{decimals:0}},
|
20
|
+
{json:"4.20",opts:{decimals:2}},
|
21
|
+
]},
|
22
|
+
{value:4.199, tests:[{json:"4.20", opts:{decimals:2}}]},
|
23
|
+
{value:4.204, tests:[{json:"4.20", opts:{decimals:2}}]},
|
24
|
+
{value:-1.9, tests:[{json:"-2", opts:{decimals:0}}]},
|
25
|
+
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
26
|
+
{value:1e23, tests:[{json:/1(?:\.0+)?e\+23/i}]},
|
27
|
+
{value:1e-9, tests:[{json:/1(?:\.0+)?e-0*9/i}]},
|
28
|
+
{value:-2.4, tests:[{json:"-2", opts:{decimals:0}}]},
|
29
|
+
|
30
|
+
{value:"foo", tests:[{json:"\"foo\""}]},
|
31
|
+
{value: :foo, tests:[{json:"\"foo\""}]},
|
32
|
+
{value:"foo\nbar", tests:[{json:"\"foo\\nbar\""}]},
|
33
|
+
|
34
|
+
{value:[1,2,3,4,[5,6,7,[8,9,10],11,12]], tests:[
|
35
|
+
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
|
36
|
+
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [5,6,7,[8,9,10],11,12]\n]", opts:{wrap:30} },
|
37
|
+
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [8,9,10],\n 11,\n 12\n ]\n]", opts:{wrap:20} },
|
38
|
+
{ json:"[\n 1,\n 2,\n 3,\n 4,\n [\n 5,\n 6,\n 7,\n [\n 8,\n 9,\n 10\n ],\n 11,\n 12\n ]\n]", opts:{wrap:true} },
|
39
|
+
{ json:"[\n\t1,\n\t2,\n\t3,\n\t4,\n\t[\n\t\t5,\n\t\t6,\n\t\t7,\n\t\t[\n\t\t\t8,\n\t\t\t9,\n\t\t\t10\n\t\t],\n\t\t11,\n\t\t12\n\t]\n]", opts:{wrap:true,indent:"\t"} },
|
40
|
+
{ json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]", opts:{array_padding:0} },
|
41
|
+
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{array_padding:1} },
|
42
|
+
{ json:"[ 1,2,3,4,[ 5,6,7,[ 8,9,10 ],11,12 ] ]", opts:{array_padding:2} },
|
43
|
+
{ json:"[1, 2, 3, 4, [5, 6, 7, [8, 9, 10], 11, 12]]", opts:{after_comma:1} },
|
44
|
+
{ json:"[ 1, 2, 3, 4, [ 5, 6, 7, [ 8, 9, 10 ], 11, 12 ] ]", opts:{after_comma:1,array_padding:1} },
|
45
|
+
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true} },
|
46
|
+
{ json:"[1,\n 2,\n 3,\n 4,\n [5,\n 6,\n 7,\n [8,\n 9,\n 10],\n 11,\n 12]]", opts:{short:true,wrap:true,after_comma:1} },
|
47
|
+
{ json:"[ 1,\n 2,\n 3,\n 4,\n [ 5,\n 6,\n 7,\n [ 8,\n 9,\n 10 ],\n 11,\n 12 ] ]", opts:{short:true,wrap:true,array_padding:1} },
|
48
|
+
]},
|
49
|
+
|
50
|
+
{value:[1,2,3], tests:[
|
51
|
+
{ json:"[1,2,3]" },
|
52
|
+
{ json:"[1 ,2 ,3]", opts:{before_comma:1} },
|
53
|
+
{ json:"[1 , 2 , 3]", opts:{around_comma:1} },
|
54
|
+
]},
|
55
|
+
|
56
|
+
{value:{b:1,a:2}, tests:[
|
57
|
+
{ json:'{"b":1,"a":2}' },
|
58
|
+
{ json:'{"a":2,"b":1}', opts:{sorted:true} },
|
59
|
+
{ json:'{"a":2, "b":1}', opts:{sorted:true,after_comma:1} },
|
60
|
+
{ json:'{"a" :2,"b" :1}', opts:{sorted:true,before_colon:1} },
|
61
|
+
{ json:'{"a": 2,"b": 1}', opts:{sorted:true,after_colon:1} },
|
62
|
+
{ json:'{"a" : 2,"b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1} },
|
63
|
+
{ json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1} },
|
64
|
+
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,padding:1} },
|
65
|
+
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:1,after_comma:1,object_padding:1} },
|
66
|
+
{ json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,array_padding:1} },
|
67
|
+
{ json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:2,after_comma:1,padding:2} },
|
68
|
+
{ json:'{ "a":2, "b":1 }', opts:{sorted:true,after_comma:1,padding:2} },
|
69
|
+
{ json:'{"b": 1,"a": 2}', opts:{after_colon_1:2} },
|
70
|
+
{ json:'{"b" : 1,"a" : 2}', opts:{around_colon_1:2} },
|
71
|
+
{ json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,around_colon_1:2} },
|
72
|
+
{ json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon:1} },
|
73
|
+
{ json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon_n:1} },
|
74
|
+
{ json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
|
75
|
+
{ json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon:1} },
|
76
|
+
{ json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon_n:1} },
|
77
|
+
{ json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,after_colon_1:1} },
|
78
|
+
]},
|
79
|
+
|
80
|
+
{value:{b:1,aaa:2,cc:3}, tests:[
|
81
|
+
{ json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
|
82
|
+
{ json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
|
83
|
+
{ json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
|
84
|
+
{ json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} },
|
85
|
+
]},
|
86
|
+
|
87
|
+
{value:{a:1}, tests:[
|
88
|
+
{ json:'{"a":1}' },
|
89
|
+
{ json:"{\n \"a\":1\n}", opts:{wrap:true} },
|
90
|
+
{ json:"{\n \"a\":1\n }", opts:{wrap:true, indent_last:true} },
|
91
|
+
{ json:"{\n \"a\":1\n }", opts:{wrap:true, indent:" ", indent_last:true} },
|
92
|
+
]},
|
93
|
+
|
94
|
+
{value:{ b:17, a:42 }, tests:[
|
95
|
+
{ json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} },
|
96
|
+
]},
|
97
|
+
|
98
|
+
{value:[1,{a:2},3], tests:[
|
99
|
+
{ json:'[1,{"a":2},3]' },
|
100
|
+
{ json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
|
101
|
+
{ json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,after_comma:1} },
|
102
|
+
{ json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
|
103
|
+
{ json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} },
|
104
|
+
{ json:"[\n 1,\n {\n \"a\":2\n },\n 3\n ]", opts:{wrap:true,indent_last:true} },
|
105
|
+
]},
|
106
|
+
|
107
|
+
{value:[1,{a:2,b:3},4], tests:[
|
108
|
+
{ json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
|
109
|
+
]},
|
110
|
+
|
111
|
+
{value:{a:1,b:[2,3,4],c:3}, tests:[
|
112
|
+
{ json:'{"a":1,"b":[2,3,4],"c":3}' },
|
113
|
+
{ json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
|
114
|
+
{ json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} },
|
115
|
+
{ json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n }", opts:{wrap:true,indent_last:true} },
|
116
|
+
]},
|
117
|
+
|
118
|
+
{value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
|
119
|
+
{ json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} },
|
120
|
+
]},
|
121
|
+
|
122
|
+
{value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
|
123
|
+
{ json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} },
|
124
|
+
]},
|
125
|
+
|
126
|
+
{value:{"abcdefghij"=>[{"abcdefghijklmnop"=>{}}]}, tests:[
|
127
|
+
{ json:"{\"abcdefghij\":[{\"abcdefghijklmnop\":{}}]}" },
|
128
|
+
{ json:"{\"abcdefghij\" : [{\"abcdefghijklmnop\" : {}}]}", opts:{wrap:1, short:true, around_colon_n:1} },
|
129
|
+
]},
|
130
|
+
|
131
|
+
{value:{foo:{}}, tests:[
|
132
|
+
{ json:"{\"foo\":{}}" },
|
133
|
+
{ json:"{\"foo\":{}}", opts:{wrap:false} },
|
134
|
+
{ json:"{\n \"foo\":{}\n}", opts:{wrap:5} },
|
135
|
+
{ json:"{\"foo\":{}}", opts:{wrap:1, short:true} },
|
136
|
+
]},
|
137
|
+
|
138
|
+
{value:["foo",{},"bar"], tests:[
|
139
|
+
{ json:"[\n \"foo\",\n {},\n \"bar\"\n]", opts:{wrap:1} },
|
140
|
+
{ json:"[\"foo\",\n {},\n \"bar\"]", opts:{wrap:1, short:true} },
|
141
|
+
]},
|
142
|
+
|
143
|
+
{value:["foo",[],"bar"], tests:[
|
144
|
+
{ json:"[\n \"foo\",\n [],\n \"bar\"\n]", opts:{wrap:1} },
|
145
|
+
{ json:"[\"foo\",\n [],\n \"bar\"]", opts:{wrap:1, short:true} },
|
146
|
+
]},
|
147
|
+
|
148
|
+
{value:["foo",[{},[{foo:[]},42]],"bar"], tests:[
|
149
|
+
{ json:"[\"foo\",\n [{},\n [{\"foo\":[]},\n 42]],\n \"bar\"]", opts:{wrap:1, short:true} },
|
150
|
+
]},
|
151
|
+
|
152
|
+
{value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
|
153
|
+
{ json:'{ "a":1}' },
|
154
|
+
{ json:'{ "a":1}', opts:{wrap:true} },
|
155
|
+
{ json:'{"a":1}', opts:{indent:''} },
|
156
|
+
]},
|
157
|
+
|
158
|
+
{value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
|
159
|
+
{ json:'{"a":1}' },
|
160
|
+
{ json:"{\n \"a\":1\n}", opts:{wrap:true} },
|
161
|
+
]},
|
162
|
+
|
163
|
+
{value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
|
164
|
+
{ json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
|
165
|
+
{ json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
|
166
|
+
{ json:"{\n \"a\":{\n \"b\":{\n \"c\":{\n \"d\":{\n \"e\":{\n \"f\":{\n \"g\":{\n \"h\":{\n \"i\":{\n \"j\":{\n \"k\":{\n \"l\":{\n \"m\":1\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n}", opts:{wrap:1} },
|
167
|
+
]}
|
168
|
+
]
|
169
|
+
|