Skip to content

Commit

Permalink
fix(test): add tests for atom_key and return_plain opts for hocon_sch…
Browse files Browse the repository at this point in the history
…ema:map/4
  • Loading branch information
terry-xiaoyu committed Jun 22, 2021
1 parent c770db9 commit 243bb86
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/hocon_schema_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,26 @@ atom_key_array_test() ->
},
Conf = "arr = [{id = 1}, {id = 2}]",
{ok, PlainMap} = hocon:binary(Conf, #{}),
?assertEqual(#{arr => [#{id => 1}, #{id => 2}]},
hocon_schema:check_plain(Sc, PlainMap, #{atom_key => true})).
return_plain_test() ->
[ ?assertEqual(#{arr => [#{id => 1}, #{id => 2}]},
hocon_schema:check_plain(Sc, PlainMap, #{atom_key => true}))
, ?assertMatch({_, #{arr := [#{id := 1}, #{id := 2}]}},
hocon_schema:map(Sc, PlainMap, all, #{is_richmap => false, atom_key => true}))
].

return_plain_test_() ->
Sc = #{structs => [?VIRTUAL_ROOT],
fields => [ {metadata, hoconsc:t(string())}
, {type, hoconsc:t(string())}
, {value, hoconsc:t(string())}
]},
StrConf = "type=t, metadata=m, value=v",
{ok, M} = hocon:binary(StrConf, #{format => richmap}),
?assertMatch(#{metadata := "m", type := "t", value := "v"},
hocon_schema:check(Sc, M, #{atom_key => true, return_plain => true})).
{ok, Conf} = hocon:binary(StrConf, #{format => richmap}),
Opts = #{atom_key => true, return_plain => true},
[ ?_assertMatch(#{metadata := "m", type := "t", value := "v"},
hocon_schema:check(Sc, Conf, Opts))
, ?_assertMatch({_, #{metadata := "m", type := "t", value := "v"}},
hocon_schema:map(Sc, Conf, all, Opts))
].

validator_test() ->
Sc = #{structs => [?VIRTUAL_ROOT],
Expand Down

0 comments on commit 243bb86

Please sign in to comment.