neatjson 0.6.2 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
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.2"
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
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
- {value:{b:1,a:2}, tests:[
59
- { json:'{"b":1,"a":2}' },
60
- { json:'{"a":2,"b":1}', opts:{sorted:true} },
61
- { json:'{"a":2, "b":1}', opts:{sorted:true,afterComma:1} },
62
- { json:'{"a" :2,"b" :1}', opts:{sorted:true,beforeColon:1} },
63
- { json:'{"a": 2,"b": 1}', opts:{sorted:true,afterColon:1} },
64
- { json:'{"a" : 2,"b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1} },
65
- { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1} },
66
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,padding:1} },
67
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:1,afterComma:1,objectPadding:1} },
68
- { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,arrayPadding:1} },
69
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:2,afterComma:1,padding:2} },
70
- { json:'{ "a":2, "b":1 }', opts:{sorted:true,afterComma:1,padding:2} },
71
- { json:'{"b": 1,"a": 2}', opts:{afterColon1:2} },
72
- { json:'{"b" : 1,"a" : 2}', opts:{aroundColon1:2} },
73
- { json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,aroundColon1:2} },
74
- { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColon:1} },
75
- { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColonN:1} },
76
- { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
77
- { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColon:1} },
78
- { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColonN:1} },
79
- { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,afterColon1:1} }
80
- ]},
81
-
82
- {value:{b:1,aaa:2,cc:3}, tests:[
83
- { json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
84
- { json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
85
- { json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
86
- { json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} }
87
- ]},
88
-
89
- {value:{a:1}, tests:[
90
- { json:'{"a":1}' },
91
- { json:"{\n \"a\":1\n}", opts:{wrap: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,afterComma: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
- ]},
105
-
106
- {value:[1,{a:2,b:3},4], tests:[
107
- { json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
108
- ]},
109
-
110
- {value:{a:1,b:[2,3,4],c:3}, tests:[
111
- { json:'{"a":1,"b":[2,3,4],"c":3}' },
112
- { json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
113
- { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} }
114
- ]},
115
-
116
- {value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
117
- { json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} }
118
- ]},
119
-
120
- {value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
121
- { json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} }
122
- ]},
123
-
124
- {value:{"abcdefghij":[{"abcdefghijklmnop":{}}]}, tests:[
125
- { json:'{"abcdefghij":[{"abcdefghijklmnop":{}}]}' },
126
- { json:'{"abcdefghij" : [{"abcdefghijklmnop" : {}}]}', opts:{wrap:1, short:true, aroundColonN:1} },
127
- ]},
128
-
129
- {value:{"foo":{}}, tests:[
130
- { json:'{"foo":{}}' },
131
- { json:'{"foo":{}}', opts:{wrap:false} },
132
- { json:'{\n "foo":{}\n}', opts:{wrap:5} },
133
- { json:'{"foo":{}}', opts:{wrap:1, short:true} }
134
- ]},
135
-
136
- {value:["foo",{},"bar"], tests:[
137
- { json:'[\n "foo",\n {},\n "bar"\n]', opts:{wrap:1} },
138
- { json:'["foo",\n {},\n "bar"]', opts:{wrap:1, short:true} }
139
- ]},
140
-
141
- {value:["foo",[],"bar"], tests:[
142
- { json:'[\n "foo",\n [],\n "bar"\n]', opts:{wrap:1} },
143
- { json:'["foo",\n [],\n "bar"]', opts:{wrap:1, short:true} }
144
- ]},
145
-
146
- {value:["foo",[{},[{"foo":[]},42]],"bar"], tests:[
147
- { json:'["foo",\n [{},\n [{"foo":[]},\n 42]],\n "bar"]', opts:{wrap:1, short:true} },
148
- ]},
149
-
150
- {value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
151
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
152
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
153
- { 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} },
154
- ]}
155
-
156
- // {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
157
- // { json:'{ "a":1}' },
158
- // { json:'{ "a":1}', opts:{wrap:true} },
159
- // { json:'{"a":1}', opts:{indent:''} },
160
- // ]},
161
-
162
- // {value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
163
- // { json:'{"a":1}' },
164
- // { json:"{\n \"a\":1\n}", opts:{wrap:true} }
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}", opts:{wrap:true} }
90
- ]},
91
-
92
- {value:{ b:17, a:42 }, tests:[
93
- { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} }
94
- ]},
95
-
96
- {value:[1,{a:2},3], tests:[
97
- { json:'[1,{"a":2},3]' },
98
- { json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
99
- { json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,after_comma:1} },
100
- { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
101
- { json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} }
102
- ]},
103
-
104
- {value:[1,{a:2,b:3},4], tests:[
105
- { json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
106
- ]},
107
-
108
- {value:{a:1,b:[2,3,4],c:3}, tests:[
109
- { json:'{"a":1,"b":[2,3,4],"c":3}' },
110
- { json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
111
- { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} }
112
- ]},
113
-
114
- {value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
115
- { json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} }
116
- ]},
117
-
118
- {value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
119
- { json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} }
120
- ]},
121
-
122
- {value:{"abcdefghij"=>[{"abcdefghijklmnop"=>{}}]}, tests:[
123
- { json:"{\"abcdefghij\":[{\"abcdefghijklmnop\":{}}]}" },
124
- { json:"{\"abcdefghij\" : [{\"abcdefghijklmnop\" : {}}]}", opts:{wrap:1, short:true, around_colon_n:1} },
125
- ]},
126
-
127
- {value:{foo:{}}, tests:[
128
- { json:"{\"foo\":{}}" },
129
- { json:"{\"foo\":{}}", opts:{wrap:false} },
130
- { json:"{\n \"foo\":{}\n}", opts:{wrap:5} },
131
- { json:"{\"foo\":{}}", opts:{wrap:1, short:true} }
132
- ]},
133
-
134
- {value:["foo",{},"bar"], tests:[
135
- { json:"[\n \"foo\",\n {},\n \"bar\"\n]", opts:{wrap:1} },
136
- { json:"[\"foo\",\n {},\n \"bar\"]", opts:{wrap:1, short:true} }
137
- ]},
138
-
139
- {value:["foo",[],"bar"], tests:[
140
- { json:"[\n \"foo\",\n [],\n \"bar\"\n]", opts:{wrap:1} },
141
- { json:"[\"foo\",\n [],\n \"bar\"]", opts:{wrap:1, short:true} }
142
- ]},
143
-
144
- {value:["foo",[{},[{foo:[]},42]],"bar"], tests:[
145
- { json:"[\"foo\",\n [{},\n [{\"foo\":[]},\n 42]],\n \"bar\"]", opts:{wrap:1, short:true} },
146
- ]},
147
-
148
- {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
149
- { json:'{ "a":1}' },
150
- { json:'{ "a":1}', opts:{wrap:true} },
151
- { json:'{"a":1}', opts:{indent:''} },
152
- ]},
153
-
154
- {value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
155
- { json:'{"a":1}' },
156
- { json:"{\n \"a\":1\n}", opts:{wrap:true} }
157
- ]},
158
-
159
- {value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
160
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
161
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
162
- { 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} },
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
+