rewrote test harness to use eunit and make it easier to add future tests
This commit is contained in:
parent
f5f1f588d4
commit
ab67abd01a
37 changed files with 121 additions and 81 deletions
33
src/jsx.erl
33
src/jsx.erl
|
@ -1,17 +1,26 @@
|
|||
-module(jsx).
|
||||
|
||||
-export([decoder/0, decoder/1]).
|
||||
-export([decoder/0, decoder/2]).
|
||||
|
||||
-include("jsx_common.hrl").
|
||||
|
||||
decoder() ->
|
||||
decoder([]).
|
||||
decoder(none, []).
|
||||
|
||||
decoder(OptsList) ->
|
||||
OptsRec = parse_opts(OptsList),
|
||||
case OptsRec#opts.encoding of
|
||||
decoder(Callbacks, OptsList) ->
|
||||
Opts = parse_opts(OptsList),
|
||||
case Opts#opts.encoding of
|
||||
utf8 ->
|
||||
fun(Stream) -> jsx_utf8:start(Stream, [], [], OptsRec) end
|
||||
fun(Stream) -> jsx_utf8:start(Stream, [], init_callbacks(Callbacks), Opts) end
|
||||
; utf16-big ->
|
||||
fun(Stream) -> jsx_utf16b:start(Stream, [], init_callbacks(Callbacks), Opts) end
|
||||
; utf16-little ->
|
||||
fun(Stream) -> jsx_utf16l:start(Stream, [], init_callbacks(Callbacks), Opts) end
|
||||
; utf32-big ->
|
||||
fun(Stream) -> jsx_utf32b:start(Stream, [], init_callbacks(Callbacks), Opts) end
|
||||
; utf32-little ->
|
||||
fun(Stream) -> jsx_utf32l:start(Stream, [], init_callbacks(Callbacks), Opts) end
|
||||
;
|
||||
end.
|
||||
|
||||
|
||||
|
@ -30,5 +39,13 @@ parse_opts([{naked_values, Value}|Rest], Opts) ->
|
|||
true = lists:member(Value, [true, false]),
|
||||
parse_opts(Rest, Opts#opts{naked_values = Value});
|
||||
parse_opts([{encoding, Value}|Rest], Opts) ->
|
||||
true = lists:member(Value, [utf8]),
|
||||
parse_opts(Rest, Opts#opts{encoding = Value}).
|
||||
true = lists:member(Value, [auto, utf8, utf16-big, utf16-little, utf32-big, utf32-little]),
|
||||
parse_opts(Rest, Opts#opts{encoding = Value}).
|
||||
|
||||
init_callbacks(none) ->
|
||||
{none, []};
|
||||
init_callbacks({M, S}) when is_atom(M) ->
|
||||
{M, S};
|
||||
init_callbacks({F, S}) when is_function(F) ->
|
||||
{F, S}.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue