jsx_to_term:parse_config/2: Honor return_maps option value

Previously, no matter what the caller specified in options,
`return_maps` was always set to `true`. The only solution was to not
specify `return_maps` at all.

Unfortunately, if the caller is using a wrapper which sets default
options, including `return_maps`, it's impossible to override it. This
prevented the caller from requesting this mode if he was interested in
preserving the order of keys.

While here, add a testcase for this.
This commit is contained in:
Jean-Sébastien Pédron 2017-09-26 10:10:24 +02:00
parent 5acdc7e4f2
commit 48574d4242
No known key found for this signature in database
GPG key ID: 39E99761A5FD94CC

View file

@ -88,7 +88,7 @@ parse_config([labels|Rest], Config) ->
parse_config(Rest, Config#config{labels = binary});
parse_config([{return_maps, Val}|Rest], Config)
when Val == true; Val == false ->
parse_config(Rest, Config#config{return_maps = true});
parse_config(Rest, Config#config{return_maps = Val});
parse_config([return_maps|Rest], Config) ->
parse_config(Rest, Config#config{return_maps = true});
parse_config([{K, _}|Rest] = Options, Config) ->
@ -424,6 +424,10 @@ return_maps_test_() ->
[{}],
jsx:decode(<<"{}">>, [])
)},
{"an empty map", ?_assertEqual(
[{}],
jsx:decode(<<"{}">>, [{return_maps, false}])
)},
{"a small map", ?_assertEqual(
#{<<"awesome">> => true, <<"library">> => <<"jsx">>},
jsx:decode(<<"{\"library\": \"jsx\", \"awesome\": true}">>, [return_maps])