removed now meaningless strict option from format and verify modules and associated types and specs

This commit is contained in:
alisdair sullivan 2011-07-04 21:04:10 -07:00
parent 9eec2459f4
commit 922e3e525e
3 changed files with 8 additions and 23 deletions

View file

@ -38,11 +38,7 @@
is_json(JSON, OptsList) when is_binary(JSON) ->
P = jsx:decoder(extract_parser_opts(OptsList)),
is_json(fun() -> P(JSON) end, OptsList);
is_json(F, OptsList) when is_function(F) ->
case proplists:get_value(strict, OptsList, false) of
true -> collect_strict(F(), [[]])
; false -> collect(F(), [[]])
end.
is_json(F, _OptsList) when is_function(F) -> collect(F(), [[]]).
extract_parser_opts(Opts) ->
@ -61,14 +57,6 @@ extract_parser_opts([K|Rest], Acc) ->
end.
%% enforce only arrays and objects at top level
collect_strict({event, start_object, Next}, Keys) ->
collect(Next(), Keys);
collect_strict({event, start_array, Next}, Keys) ->
collect(Next(), Keys);
collect_strict(_, _) ->
false.
collect({event, end_json, _Next}, _Keys) ->
true;
@ -166,18 +154,18 @@ false_test_() ->
}
].
less_strict_test_() ->
naked_value_test_() ->
[
{"naked true",
?_assert(is_json(<<"true">>, [{strict, false}]) =:= true)
?_assert(is_json(<<"true">>, []) =:= true)
},
{"naked number",
?_assert(is_json(<<"1">>, [{strict, false}]) =:= true)
?_assert(is_json(<<"1">>, []) =:= true)
},
{"naked string",
?_assert(is_json(
<<"\"i am not json\"">>,
[{strict, false}]
[]
) =:= true
)
}