Skip to content

Commit

Permalink
Prevent djan failing on negative indent for h keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Dec 3, 2023
1 parent 9bda2d1 commit f925cb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## flor 1.6.2 not yet released

* Prevent djan failing on negative indent for hash keys


## flor 1.6.1 released 2023-10-20

Expand Down
2 changes: 1 addition & 1 deletion lib/flor/djan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def object_to_d(x, out, opts)
#
kml, vml =
x.inject([ 0, 0 ]) { |(kl, vl), (k, v)|
[ [ kl, len(k, opts) ].max, [ vl, len(v, opts) ].max ] }
[ [ kl, len(k.to_s, opts) ].max, [ vl, len(v, opts) ].max ] }
kml += 1
#
if i && w && i + kml + 1 + vml < w
Expand Down
18 changes: 18 additions & 0 deletions spec/djan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@
"a+b" }
}.strip)
end

it 'is ok with string keys' do

d =
{ "0": { user_id: 0, aum: 0, pitch_aum: 0, review_aum: 0, Pitch: 3, Others: 1, Social: 1, Review: 2 },
"313327975":{ user_id: 313327975, aum: 0, pitch_aum: 0, review_aum: 0, items: [], Pitch: 1, Review: 1 },
"837": { user_id: 837, aum: 0, pitch_aum: 0, review_aum: 0, items: [], Pitch: 1 },
"899": { user_id: 899, aum: 0, pitch_aum: 0, review_aum: 0, items: [], Others: 1, Social: 1, Pitch: 1, Review: 1 } }

expect(
Flor.to_djan(d, indent: 2, width: true, colours: false)
).to eq(' ' + %{
{ "0": { user_id: 0, aum: 0, pitch_aum: 0, review_aum: 0, Pitch: 3, Others: 1, Social: 1, Review: 2 },
"313327975": { user_id: 313327975, aum: 0, pitch_aum: 0, review_aum: 0, items: [], Pitch: 1, Review: 1 },
"837": { user_id: 837, aum: 0, pitch_aum: 0, review_aum: 0, items: [], Pitch: 1 },
"899": { user_id: 899, aum: 0, pitch_aum: 0, review_aum: 0, items: [], Others: 1, Social: 1, Pitch: 1, Review: 1 } }
}.strip)
end
end
end

0 comments on commit f925cb9

Please sign in to comment.