neatjson 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ TESTS.each do |value_tests|
15
15
  raise "EXPECTED:\n#{test[:json]}\nACTUAL:\n#{json}" unless test[:json]===json
16
16
  pass += 1
17
17
  rescue StandardError => e
18
- puts "Error running #{cmd}", e, ""
18
+ puts "Failure running #{cmd}", e, ""
19
19
  end
20
20
  count += 1
21
21
  if $perftesting
data/test/tests.js CHANGED
@@ -1,181 +1,183 @@
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:{sort:true} },
64
- { json:'{"a":2, "b":1}', opts:{sorted:true,afterComma:1} },
65
- { json:'{"a" :2,"b" :1}', opts:{sorted:true,beforeColon:1} },
66
- { json:'{"a": 2,"b": 1}', opts:{sorted:true,afterColon:1} },
67
- { json:'{"a" : 2,"b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1} },
68
- { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1} },
69
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,padding:1} },
70
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:1,afterComma:1,objectPadding:1} },
71
- { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,arrayPadding:1} },
72
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:2,afterComma:1,padding:2} },
73
- { json:'{ "a":2, "b":1 }', opts:{sorted:true,afterComma:1,padding:2} },
74
- { json:'{"b": 1,"a": 2}', opts:{afterColon1:2} },
75
- { json:'{"b" : 1,"a" : 2}', opts:{aroundColon1:2} },
76
- { json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,aroundColon1:2} },
77
- { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColon:1} },
78
- { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColonN:1} },
79
- { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
80
- { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColon:1} },
81
- { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColonN:1} },
82
- { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,afterColon1:1} },
83
- ]},
84
-
85
- {value:{b:1,aaa:2,cc:3}, tests:[
86
- { json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
87
- { json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
88
- { json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
89
- { json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} },
90
- ]},
91
-
92
- {value:{a:1}, tests:[
93
- { json:'{"a":1}' },
94
- { json:"{\n \"a\":1\n}", opts:{wrap:true} },
95
- { json:"{\n \"a\":1\n }", opts:{wrap:true, indentLast:true} },
96
- { json:"{\n \"a\":1\n }", opts:{wrap:true, indentLast:true, indent:" " } },
97
- ]},
98
-
99
- {value:{ b:17, a:42 }, tests:[
100
- { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} },
101
- { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sort:true, short:true} },
102
- { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sorted:true} },
103
- { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sort:true} },
104
- { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:function(k){ return k } } },
105
- { json:"{\"b\":17,\"a\":42}", opts:{wrap:false,sort:function(k,v){ return v } } },
106
- { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:function(k,v){ return -v } } },
107
- { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:function(k,v,o){ return v==o.a ? 0 : 1 } } },
108
- ]},
109
-
110
- {value:[1,{a:2},3], tests:[
111
- { json:'[1,{"a":2},3]' },
112
- { json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
113
- { json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,afterComma:1} },
114
- { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
115
- { json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} },
116
- { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n ]", opts:{wrap:true,indentLast:true} },
117
- ]},
118
-
119
- {value:[1,{a:2,b:3},4], tests:[
120
- { json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
121
- ]},
122
-
123
- {value:{a:1,b:[2,3,4],c:3}, tests:[
124
- { json:'{"a":1,"b":[2,3,4],"c":3}' },
125
- { json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
126
- { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} },
127
- { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n }", opts:{wrap:true,indentLast:true} },
128
- ]},
129
-
130
- {value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
131
- { json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} },
132
- ]},
133
-
134
- {value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
135
- { json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} },
136
- ]},
137
-
138
- {value:{"abcdefghij":[{"abcdefghijklmnop":{}}]}, tests:[
139
- { json:'{"abcdefghij":[{"abcdefghijklmnop":{}}]}' },
140
- { json:'{"abcdefghij" : [{"abcdefghijklmnop" : {}}]}', opts:{wrap:1, short:true, aroundColonN:1} },
141
- ]},
142
-
143
- {value:{"foo":{}}, tests:[
144
- { json:'{"foo":{}}' },
145
- { json:'{"foo":{}}', opts:{wrap:false} },
146
- { json:'{\n "foo":{}\n}', opts:{wrap:5} },
147
- { json:'{"foo":{}}', opts:{wrap:1, short:true} },
148
- ]},
149
-
150
- {value:["foo",{},"bar"], tests:[
151
- { json:'[\n "foo",\n {},\n "bar"\n]', opts:{wrap:1} },
152
- { json:'["foo",\n {},\n "bar"]', opts:{wrap:1, short:true} },
153
- ]},
154
-
155
- {value:["foo",[],"bar"], tests:[
156
- { json:'[\n "foo",\n [],\n "bar"\n]', opts:{wrap:1} },
157
- { json:'["foo",\n [],\n "bar"]', opts:{wrap:1, short:true} },
158
- ]},
159
-
160
- {value:["foo",[{},[{"foo":[]},42]],"bar"], tests:[
161
- { json:'["foo",\n [{},\n [{"foo":[]},\n 42]],\n "bar"]', opts:{wrap:1, short:true} },
162
- ]},
163
-
164
- {value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
165
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
166
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
167
- { 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} },
168
- ]},
169
-
170
- // {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
171
- // { json:'{ "a":1}' },
172
- // { json:'{ "a":1}', opts:{wrap:true} },
173
- // { json:'{"a":1}', opts:{indent:''} },
174
- // ]},
175
-
176
- // {value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
177
- // { json:'{"a":1}' },
178
- // { json:"{\n \"a\":1\n}", opts:{wrap:true} }
179
- // ]}
180
- ]
181
-
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:{sort:true} },
64
+ { json:'{"a":2, "b":1}', opts:{sorted:true,afterComma:1} },
65
+ { json:'{"a" :2,"b" :1}', opts:{sorted:true,beforeColon:1} },
66
+ { json:'{"a": 2,"b": 1}', opts:{sorted:true,afterColon:1} },
67
+ { json:'{"a" : 2,"b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1} },
68
+ { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1} },
69
+ { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,padding:1} },
70
+ { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:1,afterComma:1,objectPadding:1} },
71
+ { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,beforeColon:1,afterColon:1,afterComma:1,arrayPadding:1} },
72
+ { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,aroundColon:2,afterComma:1,padding:2} },
73
+ { json:'{ "a":2, "b":1 }', opts:{sorted:true,afterComma:1,padding:2} },
74
+ { json:'{"b": 1,"a": 2}', opts:{afterColon1:2} },
75
+ { json:'{"b" : 1,"a" : 2}', opts:{aroundColon1:2} },
76
+ { json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,aroundColon1:2} },
77
+ { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColon:1} },
78
+ { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,afterColonN:1} },
79
+ { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
80
+ { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColon:1} },
81
+ { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,afterColonN:1} },
82
+ { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,afterColon1:1} },
83
+ ]},
84
+
85
+ {value:{b:1,aaa:2,cc:3}, tests:[
86
+ { json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
87
+ { json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
88
+ { json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
89
+ { json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} },
90
+ ]},
91
+
92
+ {value:{a:1}, tests:[
93
+ { json:'{"a":1}' },
94
+ { json:"{\n \"a\":1\n}", opts:{wrap:true} },
95
+ { json:"{\n \"a\":1\n }", opts:{wrap:true, indentLast:true} },
96
+ { json:"{\n \"a\":1\n }", opts:{wrap:true, indentLast:true, indent:" " } },
97
+ ]},
98
+
99
+ {value:{ b:17, a:42 }, tests:[
100
+ { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} },
101
+ { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sort:true, short:true} },
102
+ { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sorted:true} },
103
+ { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sort:true} },
104
+ { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:function(k){ return k } } },
105
+ { json:"{\"b\":17,\"a\":42}", opts:{wrap:false,sort:function(k,v){ return v } } },
106
+ { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:function(k,v){ return -v } } },
107
+ { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:function(k,v,o){ return v==o.a ? 0 : 1 } } },
108
+ { json:"{\n\"b\":17,\n\"a\":42\n}", opts:{wrap:1,indent:"",sort:function(k){ return k=="a" ? 1 : 0 } } },
109
+ { json:"{\n\"a\":42,\n\"b\":17\n}", opts:{wrap:1,indent:"",sort:function(k){ return k=="a" ? 0 : 1 } } },
110
+ ]},
111
+
112
+ {value:[1,{a:2},3], tests:[
113
+ { json:'[1,{"a":2},3]' },
114
+ { json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
115
+ { json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,afterComma:1} },
116
+ { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
117
+ { json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} },
118
+ { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n ]", opts:{wrap:true,indentLast:true} },
119
+ ]},
120
+
121
+ {value:[1,{a:2,b:3},4], tests:[
122
+ { json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
123
+ ]},
124
+
125
+ {value:{a:1,b:[2,3,4],c:3}, tests:[
126
+ { json:'{"a":1,"b":[2,3,4],"c":3}' },
127
+ { json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
128
+ { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} },
129
+ { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n }", opts:{wrap:true,indentLast:true} },
130
+ ]},
131
+
132
+ {value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
133
+ { json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} },
134
+ ]},
135
+
136
+ {value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
137
+ { json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} },
138
+ ]},
139
+
140
+ {value:{"abcdefghij":[{"abcdefghijklmnop":{}}]}, tests:[
141
+ { json:'{"abcdefghij":[{"abcdefghijklmnop":{}}]}' },
142
+ { json:'{"abcdefghij" : [{"abcdefghijklmnop" : {}}]}', opts:{wrap:1, short:true, aroundColonN:1} },
143
+ ]},
144
+
145
+ {value:{"foo":{}}, tests:[
146
+ { json:'{"foo":{}}' },
147
+ { json:'{"foo":{}}', opts:{wrap:false} },
148
+ { json:'{\n "foo":{}\n}', opts:{wrap:5} },
149
+ { json:'{"foo":{}}', opts:{wrap:1, short:true} },
150
+ ]},
151
+
152
+ {value:["foo",{},"bar"], tests:[
153
+ { json:'[\n "foo",\n {},\n "bar"\n]', opts:{wrap:1} },
154
+ { json:'["foo",\n {},\n "bar"]', opts:{wrap:1, short:true} },
155
+ ]},
156
+
157
+ {value:["foo",[],"bar"], tests:[
158
+ { json:'[\n "foo",\n [],\n "bar"\n]', opts:{wrap:1} },
159
+ { json:'["foo",\n [],\n "bar"]', opts:{wrap:1, short:true} },
160
+ ]},
161
+
162
+ {value:["foo",[{},[{"foo":[]},42]],"bar"], tests:[
163
+ { json:'["foo",\n [{},\n [{"foo":[]},\n 42]],\n "bar"]', opts:{wrap:1, short:true} },
164
+ ]},
165
+
166
+ {value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
167
+ { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
168
+ { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
169
+ { 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} },
170
+ ]},
171
+
172
+ // {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
173
+ // { json:'{ "a":1}' },
174
+ // { json:'{ "a":1}', opts:{wrap:true} },
175
+ // { json:'{"a":1}', opts:{indent:''} },
176
+ // ]},
177
+
178
+ // {value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
179
+ // { json:'{"a":1}' },
180
+ // { json:"{\n \"a\":1\n}", opts:{wrap:true} }
181
+ // ]}
182
+ ]
183
+
data/test/tests.rb CHANGED
@@ -1,177 +1,179 @@
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:{sort:true} },
60
- { json:'{"a":2, "b":1}', opts:{sorted:true,after_comma:1} },
61
- { json:'{"a" :2,"b" :1}', opts:{sorted:true,before_colon:1} },
62
- { json:'{"a": 2,"b": 1}', opts:{sorted:true,after_colon:1} },
63
- { json:'{"a" : 2,"b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1} },
64
- { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1} },
65
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,padding:1} },
66
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:1,after_comma:1,object_padding:1} },
67
- { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,array_padding:1} },
68
- { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:2,after_comma:1,padding:2} },
69
- { json:'{ "a":2, "b":1 }', opts:{sorted:true,after_comma:1,padding:2} },
70
- { json:'{"b": 1,"a": 2}', opts:{after_colon_1:2} },
71
- { json:'{"b" : 1,"a" : 2}', opts:{around_colon_1:2} },
72
- { json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,around_colon_1:2} },
73
- { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon:1} },
74
- { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon_n:1} },
75
- { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
76
- { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon:1} },
77
- { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon_n:1} },
78
- { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,after_colon_1:1} },
79
- ]},
80
-
81
- {value:{b:1,aaa:2,cc:3}, tests:[
82
- { json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
83
- { json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
84
- { json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
85
- { json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} },
86
- ]},
87
-
88
- {value:{a:1}, tests:[
89
- { json:'{"a":1}' },
90
- { json:"{\n \"a\":1\n}", opts:{wrap:true} },
91
- { json:"{\n \"a\":1\n }", opts:{wrap:true, indent_last:true} },
92
- { json:"{\n \"a\":1\n }", opts:{wrap:true, indent:" ", indent_last:true} },
93
- ]},
94
-
95
- {value:{ b:17, a:42 }, tests:[
96
- { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} },
97
- { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sort:true, short:true} },
98
- { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sorted:true} },
99
- { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sort:true} },
100
- { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:->(k){ k } } },
101
- { json:"{\"b\":17,\"a\":42}", opts:{wrap:false,sort:->(k,v){ v } } },
102
- { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:->(k,v){ -v } } },
103
- { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:->(k,v,h){ v==h.values.max ? 0 : 1 } } },
104
- ]},
105
-
106
- {value:[1,{a:2},3], tests:[
107
- { json:'[1,{"a":2},3]' },
108
- { json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
109
- { json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,after_comma:1} },
110
- { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
111
- { json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} },
112
- { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n ]", opts:{wrap:true,indent_last:true} },
113
- ]},
114
-
115
- {value:[1,{a:2,b:3},4], tests:[
116
- { json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
117
- ]},
118
-
119
- {value:{a:1,b:[2,3,4],c:3}, tests:[
120
- { json:'{"a":1,"b":[2,3,4],"c":3}' },
121
- { json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
122
- { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} },
123
- { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n }", opts:{wrap:true,indent_last:true} },
124
- ]},
125
-
126
- {value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
127
- { json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} },
128
- ]},
129
-
130
- {value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
131
- { json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} },
132
- ]},
133
-
134
- {value:{"abcdefghij"=>[{"abcdefghijklmnop"=>{}}]}, tests:[
135
- { json:"{\"abcdefghij\":[{\"abcdefghijklmnop\":{}}]}" },
136
- { json:"{\"abcdefghij\" : [{\"abcdefghijklmnop\" : {}}]}", opts:{wrap:1, short:true, around_colon_n:1} },
137
- ]},
138
-
139
- {value:{foo:{}}, tests:[
140
- { json:"{\"foo\":{}}" },
141
- { json:"{\"foo\":{}}", opts:{wrap:false} },
142
- { json:"{\n \"foo\":{}\n}", opts:{wrap:5} },
143
- { json:"{\"foo\":{}}", opts:{wrap:1, short:true} },
144
- ]},
145
-
146
- {value:["foo",{},"bar"], tests:[
147
- { json:"[\n \"foo\",\n {},\n \"bar\"\n]", opts:{wrap:1} },
148
- { json:"[\"foo\",\n {},\n \"bar\"]", opts:{wrap:1, short:true} },
149
- ]},
150
-
151
- {value:["foo",[],"bar"], tests:[
152
- { json:"[\n \"foo\",\n [],\n \"bar\"\n]", opts:{wrap:1} },
153
- { json:"[\"foo\",\n [],\n \"bar\"]", opts:{wrap:1, short:true} },
154
- ]},
155
-
156
- {value:["foo",[{},[{foo:[]},42]],"bar"], tests:[
157
- { json:"[\"foo\",\n [{},\n [{\"foo\":[]},\n 42]],\n \"bar\"]", opts:{wrap:1, short:true} },
158
- ]},
159
-
160
- {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
161
- { json:'{ "a":1}' },
162
- { json:'{ "a":1}', opts:{wrap:true} },
163
- { json:'{"a":1}', opts:{indent:''} },
164
- ]},
165
-
166
- {value:Class.new{ def to_json(*a); JSON.neat_generate({a:1},*a); end }.new, tests:[
167
- { json:'{"a":1}' },
168
- { json:"{\n \"a\":1\n}", opts:{wrap:true} },
169
- ]},
170
-
171
- {value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
172
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
173
- { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
174
- { 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} },
175
- ]}
176
- ]
177
-
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:{sort:true} },
60
+ { json:'{"a":2, "b":1}', opts:{sorted:true,after_comma:1} },
61
+ { json:'{"a" :2,"b" :1}', opts:{sorted:true,before_colon:1} },
62
+ { json:'{"a": 2,"b": 1}', opts:{sorted:true,after_colon:1} },
63
+ { json:'{"a" : 2,"b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1} },
64
+ { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1} },
65
+ { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,padding:1} },
66
+ { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:1,after_comma:1,object_padding:1} },
67
+ { json:'{"a" : 2, "b" : 1}', opts:{sorted:true,before_colon:1,after_colon:1,after_comma:1,array_padding:1} },
68
+ { json:'{ "a" : 2, "b" : 1 }', opts:{sorted:true,around_colon:2,after_comma:1,padding:2} },
69
+ { json:'{ "a":2, "b":1 }', opts:{sorted:true,after_comma:1,padding:2} },
70
+ { json:'{"b": 1,"a": 2}', opts:{after_colon_1:2} },
71
+ { json:'{"b" : 1,"a" : 2}', opts:{around_colon_1:2} },
72
+ { json:"{\n \"b\":1,\n \"a\":2\n}", opts:{wrap:true,around_colon_1:2} },
73
+ { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon:1} },
74
+ { json:"{\n \"b\": 1,\n \"a\": 2\n}", opts:{wrap:true,after_colon_n:1} },
75
+ { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true} },
76
+ { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon:1} },
77
+ { json:"{\"b\": 1,\n \"a\": 2}", opts:{wrap:true,short:true,after_colon_n:1} },
78
+ { json:"{\"b\":1,\n \"a\":2}", opts:{wrap:true,short:true,after_colon_1:1} },
79
+ ]},
80
+
81
+ {value:{b:1,aaa:2,cc:3}, tests:[
82
+ { json:"{\n \"b\":1,\n \"aaa\":2,\n \"cc\":3\n}", opts:{wrap:true} },
83
+ { json:"{\n \"b\" :1,\n \"aaa\":2,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true} },
84
+ { json:"{\"b\":1,\"aaa\":2,\"cc\":3}", opts:{aligned:true} },
85
+ { json:"{\n \"aaa\":2,\n \"b\" :1,\n \"cc\" :3\n}", opts:{wrap:true,aligned:true,sorted:true} },
86
+ ]},
87
+
88
+ {value:{a:1}, tests:[
89
+ { json:'{"a":1}' },
90
+ { json:"{\n \"a\":1\n}", opts:{wrap:true} },
91
+ { json:"{\n \"a\":1\n }", opts:{wrap:true, indent_last:true} },
92
+ { json:"{\n \"a\":1\n }", opts:{wrap:true, indent:" ", indent_last:true} },
93
+ ]},
94
+
95
+ {value:{ b:17, a:42 }, tests:[
96
+ { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sorted:true,short:true} },
97
+ { json:"{\"a\":42,\n \"b\":17}", opts:{wrap:10,sort:true, short:true} },
98
+ { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sorted:true} },
99
+ { json:"{\n \"a\":42,\n \"b\":17\n}", opts:{wrap:1,sort:true} },
100
+ { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:->(k){ k } } },
101
+ { json:"{\"b\":17,\"a\":42}", opts:{wrap:false,sort:->(k,v){ v } } },
102
+ { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:->(k,v){ -v } } },
103
+ { json:"{\"a\":42,\"b\":17}", opts:{wrap:false,sort:->(k,v,h){ v==h.values.max ? 0 : 1 } } },
104
+ { json:"{\n\"b\":17,\n\"a\":42\n}", opts:{wrap:1,indent:"",sort:->(k,v){ k==:a ? 1 : 0 } } },
105
+ { json:"{\n\"a\":42,\n\"b\":17\n}", opts:{wrap:1,indent:"",sort:->(k,v){ k==:a ? 0 : 1 } } },
106
+ ]},
107
+
108
+ {value:[1,{a:2},3], tests:[
109
+ { json:'[1,{"a":2},3]' },
110
+ { json:'[ 1,{ "a":2 },3 ]', opts:{padding:1} },
111
+ { json:'[ 1, { "a":2 }, 3 ]', opts:{padding:1,after_comma:1} },
112
+ { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n]", opts:{wrap:true} },
113
+ { json:"[\n 1,\n {\"a\":2},\n 3\n]", opts:{wrap:10} },
114
+ { json:"[\n 1,\n {\n \"a\":2\n },\n 3\n ]", opts:{wrap:true,indent_last:true} },
115
+ ]},
116
+
117
+ {value:[1,{a:2,b:3},4], tests:[
118
+ { json:"[1,\n {\"a\":2,\n \"b\":3},\n 4]", opts:{wrap:0,short:true} },
119
+ ]},
120
+
121
+ {value:{a:1,b:[2,3,4],c:3}, tests:[
122
+ { json:'{"a":1,"b":[2,3,4],"c":3}' },
123
+ { json:"{\n \"a\":1,\n \"b\":[2,3,4],\n \"c\":3\n}", opts:{wrap:10} },
124
+ { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n}", opts:{wrap:true} },
125
+ { json:"{\n \"a\":1,\n \"b\":[\n 2,\n 3,\n 4\n ],\n \"c\":3\n }", opts:{wrap:true,indent_last:true} },
126
+ ]},
127
+
128
+ {value:{hooo:42,whee:['yaaa','oooo','booy'],zoop:"whoop"}, tests:[
129
+ { json:"{\"hooo\":42,\n \"whee\":[\"yaaa\",\n \"oooo\",\n \"booy\"],\n \"zoop\":\"whoop\"}", opts:{wrap:20,short:true} },
130
+ ]},
131
+
132
+ {value:{ a:[ {x:"foo",y:"jim"}, {x:"bar",y:"jam"} ] }, tests:[
133
+ { json:"{\"a\":[{\"x\":\"foo\",\n \"y\":\"jim\"},\n {\"x\":\"bar\",\n \"y\":\"jam\"}]}", opts:{wrap:true,short:true} },
134
+ ]},
135
+
136
+ {value:{"abcdefghij"=>[{"abcdefghijklmnop"=>{}}]}, tests:[
137
+ { json:"{\"abcdefghij\":[{\"abcdefghijklmnop\":{}}]}" },
138
+ { json:"{\"abcdefghij\" : [{\"abcdefghijklmnop\" : {}}]}", opts:{wrap:1, short:true, around_colon_n:1} },
139
+ ]},
140
+
141
+ {value:{foo:{}}, tests:[
142
+ { json:"{\"foo\":{}}" },
143
+ { json:"{\"foo\":{}}", opts:{wrap:false} },
144
+ { json:"{\n \"foo\":{}\n}", opts:{wrap:5} },
145
+ { json:"{\"foo\":{}}", opts:{wrap:1, short:true} },
146
+ ]},
147
+
148
+ {value:["foo",{},"bar"], tests:[
149
+ { json:"[\n \"foo\",\n {},\n \"bar\"\n]", opts:{wrap:1} },
150
+ { json:"[\"foo\",\n {},\n \"bar\"]", opts:{wrap:1, short:true} },
151
+ ]},
152
+
153
+ {value:["foo",[],"bar"], tests:[
154
+ { json:"[\n \"foo\",\n [],\n \"bar\"\n]", opts:{wrap:1} },
155
+ { json:"[\"foo\",\n [],\n \"bar\"]", opts:{wrap:1, short:true} },
156
+ ]},
157
+
158
+ {value:["foo",[{},[{foo:[]},42]],"bar"], tests:[
159
+ { json:"[\"foo\",\n [{},\n [{\"foo\":[]},\n 42]],\n \"bar\"]", opts:{wrap:1, short:true} },
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
+ {value:{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:1}}}}}}}}}}}}}, tests:[
174
+ { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:false} },
175
+ { json:'{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":1}}}}}}}}}}}}}', opts:{wrap:1,short:true} },
176
+ { 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} },
177
+ ]}
178
+ ]
179
+