is_json inputs now line up with format inputs

This commit is contained in:
alisdair sullivan 2011-07-17 20:53:33 -07:00
parent fd3c6af50b
commit e7025efe50
2 changed files with 25 additions and 5 deletions

View file

@ -110,25 +110,30 @@ term_to_json(JSON, Opts) ->
end.
-spec is_json(JSON::binary()) -> true | false.
-spec is_json(JSON::binary()) -> true | false
; (Terms::list(jsx_encodeable())) -> true | false.
is_json(JSON) ->
is_json(JSON, []).
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false.
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false
; (Terms::list(jsx_encodeable()), Opts::verify_opts()) -> true | false.
is_json(JSON, Opts) ->
jsx_verify:is_json(JSON, Opts).
-spec format(JSON::binary()) -> binary() | iolist().
-spec format(JSON::binary()) -> binary() | iolist()
; (Terms::list(jsx_encodeable())) -> binary() | iolist().
format(JSON) ->
format(JSON, []).
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist().
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist()
; (Terms::list(jsx_encodeable()), Opts::format_opts()) ->
binary() | iolist().
format(JSON, Opts) ->
jsx_format:format(JSON, Opts).

View file

@ -34,11 +34,15 @@
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false
; (Terms::list(jsx_encodeable()), Opts::verify_opts()) -> true | false
; (F::jsx_iterator(), Opts::verify_opts()) -> true | false.
is_json(JSON, OptsList) when is_binary(JSON) ->
P = jsx:decoder(extract_parser_opts(OptsList)),
is_json(fun() -> P(JSON) end, OptsList);
is_json(Terms, OptsList) when is_list(Terms) ->
P = jsx:encoder(),
is_json(fun() -> P(Terms) end, OptsList);
is_json(F, OptsList) when is_function(F) ->
Opts = parse_opts(OptsList, #verify_opts{}),
case Opts#verify_opts.naked_values of
@ -222,7 +226,18 @@ naked_value_test_() ->
) =:= false
)
}
].
].
terms_test_() ->
[
{"terms",
?_assert(is_json([start_object,
{key, "key"},
{string, "value"},
end_object
], []) =:= true
)}
].
-endif.