neatjson 0.10 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neatjson.rb +3 -2
- data/neatjson.gemspec +1 -1
- data/test/tests.js +8 -0
- data/test/tests.lua +14 -5
- data/test/tests.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9896a4ef60379130606c3de3b7ce03ed65ce304ce7998470ecb74aaa95878f62
|
4
|
+
data.tar.gz: 7aa2196577ba6862be5bdf3811c6e2752157aa7b1520bae37697020a1d65d1cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 867bb6fa6cd5af52f708ded86d50adaf1b938e5f114c05cb9801ec40cf7ff0f08e1547400bf98f42087db2b0520eb682e85f88da9a3176f8ad61b611c8bd4944
|
7
|
+
data.tar.gz: b6b3d72a566b76b50baa82a7fde278f0b0a0c954e698c67fab36d835cf12cae7b1f9a56b5a0fd081ee94501735b6bbea439934057e91ca8f2607d1212ca70574
|
data/lib/neatjson.rb
CHANGED
@@ -118,7 +118,7 @@ module JSON
|
|
118
118
|
when 3 then o.sort_by{ |k,v| sort[k,v,o] }
|
119
119
|
end
|
120
120
|
end
|
121
|
-
keys = o.map{|x| x.first.to_s }
|
121
|
+
keys = o.map{ |x| x.first.to_s }
|
122
122
|
keyvals = o.map.with_index{ |(k,v),i| [ k.to_s.inspect, build[v, '', opts[:force_floats] || opts[:force_floats_in].include?(keys[i])] ] }
|
123
123
|
keyvals = keyvals.map{ |kv| kv.join(colon1) }.join(comma)
|
124
124
|
one_line = "#{indent}{#{opad}#{keyvals}#{opad}}"
|
@@ -152,7 +152,8 @@ module JSON
|
|
152
152
|
keyvals.map!{ |k,v| [ formatk % k,v] }
|
153
153
|
end
|
154
154
|
indent2 = "#{indent}#{opts[:indent]}"
|
155
|
-
keyvals.map
|
155
|
+
keyvals.map!.with_index do |(k,v),i|
|
156
|
+
floats_forced = opts[:force_floats] || opts[:force_floats_in].include?(keys[i])
|
156
157
|
one_line = "#{k}#{colonn}#{build[v, '', floats_forced]}"
|
157
158
|
if opts[:wrap] && (one_line.length > opts[:wrap]) && (v.is_a?(Array) || v.is_a?(Hash))
|
158
159
|
"#{k}#{colonn}#{build[v, indent2, floats_forced].lstrip}"
|
data/neatjson.gemspec
CHANGED
data/test/tests.js
CHANGED
@@ -203,6 +203,14 @@ exports.tests = [
|
|
203
203
|
{ json:'[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts:{forceFloatsIn:['a'], wrap:false} },
|
204
204
|
]},
|
205
205
|
|
206
|
+
{value:[1,2,3, {bar:[4,5,6], foo:[7,8,9]}], tests:[
|
207
|
+
{ json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7,8,9]\n\t}\n]', opts:{wrap:20, indent:"\t"} },
|
208
|
+
{ json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7,8,9]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloatsIn:['bar']} },
|
209
|
+
{ json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloatsIn:['foo']} },
|
210
|
+
{ json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloatsIn:['foo', 'bar']} },
|
211
|
+
{ json:'[\n\t1.0,\n\t2.0,\n\t3.0,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloats:true} },
|
212
|
+
]},
|
213
|
+
|
206
214
|
// {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
|
207
215
|
// { json:'{ "a":1}' },
|
208
216
|
// { json:'{ "a":1}', opts:{wrap:true} },
|
data/test/tests.lua
CHANGED
@@ -208,9 +208,18 @@ return {
|
|
208
208
|
{ json='{"floats":[0.0,1.0,0.1,1.556],"raw":[0,1,0.1,1.556]}', opts={forceFloatsIn={'floats'}, decimals=3, trimTrailingZeros=true, sort=true} },
|
209
209
|
}},
|
210
210
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
211
|
+
{value={1,2,3,{a={4,5,{a=6, b=7}}, b={8,9,{a=10, b=11}}}}, tests={
|
212
|
+
{ json='[1,2,3,{"a":[4,5,{"a":6,"b":7}],"b":[8,9,{"a":10,"b":11}]}]', opts={sort=true} },
|
213
|
+
{ json='[1.0,2.0,3.0,{"a":[4.0,5.0,{"a":6.0,"b":7.0}],"b":[8.0,9.0,{"a":10.0,"b":11.0}]}]', opts={forceFloats=true, wrap=false, sort=true} },
|
214
|
+
{ json='[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts={forceFloatsIn={'a'}, wrap=false, sort=true} },
|
215
|
+
}},
|
216
|
+
|
217
|
+
{value={1,2,3, {bar={4,5,6}, foo={7,8,9}}}, tests={
|
218
|
+
{ json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7,8,9]\n\t}\n]', opts={wrap=30, sort=true, indent="\t"} },
|
219
|
+
{ json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7,8,9]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloatsIn={'bar'}} },
|
220
|
+
{ json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloatsIn={'foo'}} },
|
221
|
+
{ json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloatsIn={'foo', 'bar'}} },
|
222
|
+
{ json='[\n\t1.0,\n\t2.0,\n\t3.0,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloats=true} },
|
223
|
+
}},
|
224
|
+
|
216
225
|
}
|
data/test/tests.rb
CHANGED
@@ -218,5 +218,13 @@ TESTS = [
|
|
218
218
|
{ json:'[1.0,2.0,3.0,{"a":[4.0,5.0,{"a":6.0,"b":7.0}],"b":[8.0,9.0,{"a":10.0,"b":11.0}]}]', opts:{force_floats:true, wrap:false} },
|
219
219
|
{ json:'[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts:{force_floats_in:['a'], wrap:false} },
|
220
220
|
]},
|
221
|
+
|
222
|
+
{value:[1,2,3, {bar:[4,5,6], foo:[7,8,9]}], tests:[
|
223
|
+
{ json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7,8,9]\n\t}\n]}, opts:{wrap:20, indent:"\t"} },
|
224
|
+
{ json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7,8,9]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats_in:["bar"]} },
|
225
|
+
{ json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats_in:["foo"]} },
|
226
|
+
{ json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats_in:["foo", "bar"]} },
|
227
|
+
{ json:%Q{[\n\t1.0,\n\t2.0,\n\t3.0,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats:true} },
|
228
|
+
]},
|
221
229
|
]
|
222
230
|
|