[ruby/json] fix for pretty_generate throwing wrong number of arguments error
https://github.com/ruby/json/commit/8433571dcf
This commit is contained in:
parent
57e4176649
commit
3468811ed1
@ -490,7 +490,7 @@ module JSON
|
||||
# }
|
||||
#
|
||||
def pretty_generate(obj, opts = nil)
|
||||
return state.generate(obj) if State === opts
|
||||
return opts.generate(obj) if State === opts
|
||||
|
||||
options = PRETTY_GENERATE_OPTIONS
|
||||
|
||||
|
@ -122,6 +122,22 @@ class JSONGeneratorTest < Test::Unit::TestCase
|
||||
assert_equal '666', pretty_generate(666)
|
||||
end
|
||||
|
||||
def test_generate_pretty_custom
|
||||
state = State.new(:space_before => "<psb>", :space => "<ps>", :indent => "<pi>", :object_nl => "\n<po_nl>\n", :array_nl => "<pa_nl>")
|
||||
json = pretty_generate({1=>{}, 2=>['a','b'], 3=>4}, state)
|
||||
assert_equal(<<~'JSON'.chomp, json)
|
||||
{
|
||||
<po_nl>
|
||||
<pi>"1"<psb>:<ps>{},
|
||||
<po_nl>
|
||||
<pi>"2"<psb>:<ps>[<pa_nl><pi><pi>"a",<pa_nl><pi><pi>"b"<pa_nl><pi>],
|
||||
<po_nl>
|
||||
<pi>"3"<psb>:<ps>4
|
||||
<po_nl>
|
||||
}
|
||||
JSON
|
||||
end
|
||||
|
||||
def test_generate_custom
|
||||
state = State.new(:space_before => " ", :space => " ", :indent => "<i>", :object_nl => "\n", :array_nl => "<a_nl>")
|
||||
json = generate({1=>{2=>3,4=>[5,6]}}, state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user