added test for multi_terms
This commit is contained in:
parent
1320241e68
commit
0a96a059a1
3 changed files with 60 additions and 40 deletions
|
@ -68,12 +68,7 @@ parse_opts([{escaped_unicode, Value}|Rest], {Comments, _EscapedUnicode, Multi})
|
|||
true = lists:member(Value, [ascii, codepoint, none]),
|
||||
parse_opts(Rest, {Comments, Value, Multi});
|
||||
parse_opts([{multi_term, Value}|Rest], {Comments, EscapedUnicode, _Multi}) ->
|
||||
ok = case Value of
|
||||
S when is_binary(S) -> ok
|
||||
; whitespace -> ok
|
||||
; true -> ok
|
||||
; false -> ok
|
||||
end,
|
||||
true = lists:member(Value, [true, false]),
|
||||
parse_opts(Rest, {Comments, EscapedUnicode, Value});
|
||||
parse_opts([{encoding, _}|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts).
|
||||
|
|
|
@ -88,12 +88,13 @@ maybe_done(<<?comma/?encoding, Rest/binary>>, [array|_] = Stack, Opts) ->
|
|||
value(Rest, Stack, Opts);
|
||||
maybe_done(<<?solidus/?encoding, Rest/binary>>, Stack, ?comments_enabled(Opts)) ->
|
||||
maybe_comment(Rest, fun(Resume) -> maybe_done(Resume, Stack, Opts) end);
|
||||
maybe_done(Bin, [], ?multi_term(Opts)) ->
|
||||
{event, end_json, fun(Stream) ->
|
||||
Rest = strip(<<Bin/binary, Stream/binary>>, Opts),
|
||||
start(<<Bin/binary, Stream/binary>>, [], Opts) end};
|
||||
maybe_done(Rest, [], ?multi_term(Opts)) ->
|
||||
{event, end_json, fun() -> start(Rest, [], Opts) end};
|
||||
maybe_done(<<>>, [], Opts) ->
|
||||
{event, end_json, fun(Stream) -> maybe_done(Stream, [], Opts) end};
|
||||
{incomplete,
|
||||
fun(Stream) -> maybe_done(Stream, [], Opts) end,
|
||||
fun() -> {event, end_json, fun() -> maybe_done(<<>>, [], Opts) end} end
|
||||
};
|
||||
maybe_done(Bin, Stack, Opts) ->
|
||||
?incomplete(?partial_codepoint(Bin),
|
||||
fun(Stream) -> maybe_done(<<Bin/binary, Stream/binary>>, Stack, Opts) end,
|
||||
|
@ -673,15 +674,4 @@ maybe_comment_done(Bin, Resume) ->
|
|||
?incomplete(?partial_codepoint(Bin),
|
||||
fun(Stream) -> maybe_comment_done(<<Bin/binary, Stream/binary>>, Resume) end,
|
||||
?ferror
|
||||
).
|
||||
|
||||
|
||||
%% strip whitespace and comments (if enabled) from a stream, returning the
|
||||
%% stream when the first non-whitespace/comment character is encountered
|
||||
|
||||
strip(<<S/?encoding, Rest/binary>>, Opts) when ?is_whitespace(S) ->
|
||||
strip(Rest, Opts);
|
||||
strip(<<?solidus/?encoding, Rest/binary>>, ?comments_enabled(Opts)) ->
|
||||
maybe_comment(Rest, fun(Resume) -> strip(Resume, Opts) end);
|
||||
strip(Bin, _Opts) ->
|
||||
Bin.
|
||||
).
|
Loading…
Add table
Add a link
Reference in a new issue