Closed bwl21 closed 8 years ago
The summary is unclear. To file a bug report, please include actual code, what you expected as the output, and what you got instead.
I've just spent 15 minutes trying to figure out what bug you might be seeing, and I cannot reproduce anything that looks wrong. The following, for example, seems correct to me:
$ node
x = require('./neatjson.js')
o = [1,[],2,{},[{}],{a:[]},[[]],{o:{}}]
console.log( x.neatJSON( o, { wrap:1, short:true } ) )
// [1,
// [],
// 2,
// {},
// [{}],
// {"a":[]},
// [[]],
// {"o":{}}]
$ irb
require 'neatjson'
#=> true
o = [ 1, [], 2, {}, [{}], {a:[]}, [[]], {o:{}} ]
puts JSON.neat_generate( o, wrap:1, short:true )
#=> [1,
#=> [],
#=> 2,
#=> {},
#=> [{}],
#=> {"a":[]},
#=> [[]],
#=> {"o":{}}]
I tried to add a test but could not make the issue occur. So it seems to be on opal. It is more effort to setup the test with opal. Nevertheless, I propose to reopen the issue until we can clarify the issue.
I managed to reproduce the issiue with opal-rpl
install the opal gem:
gem install opal
test> opal-repl ../lib/neatjson.rb
>> JSON.neat_generate([ 1, [], 2, {}, [{}], {a:[]}, [[]], {o:{}} ])
=> "[]"
>> JSON.neat_generate({a:{b:[]}})
=> "[]"
>> JSON.neat_generate({a:{b:{}}})
=> "{}"
>> JSON.neat_generate({a:{b:{a:1}}})
=> "{\"a\":{\"b\":{\"a\":1}}}"
>> JSON.neat_generate({a:{b:[1]}})
=> "{\"a\":{\"b\":[1]}}"
>>
I need to work with the opal guys to run the test suite with opal
I could boil it down to a pattern which reveals some different behavior between ruby and opal with respect of lambda vs proc (https://github.com/opal/opal/issues/260)
Is there a chance that you accept the PR (see commit 42bff09) such that neatjson also can be used with Opal?
Commit 0594535 should fix this problem for you for Opal
The sumary says it all.