Skip to content

Commit

Permalink
Fix decode stream state type (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamthome authored Aug 7, 2024
1 parent 610c8dd commit 2baa937
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/euneus_decoder.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@

-type codec_callback() :: fun((binary()) -> next | {halt, term()}).

% The correct type is 'json:continuation_state()', but dialyzer says it is wrong.
-type stream_state() :: term().

-type stream_result() ::
{continue, json:continuation_state()}
{continue, stream_state()}
| {end_of_input, term()}.

-type stream_state() ::
json:continuation_state()
| tuple().

%% --------------------------------------------------------------------
%% DocTest
%% --------------------------------------------------------------------
Expand Down
7 changes: 1 addition & 6 deletions test/euneus_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,11 @@ decode_iodata_test(Config) when is_list(Config) ->
].

decode_stream_test(Config) when is_list(Config) ->
State = stream_continue_state(euneus:decode_stream_start(<<"{\"foo\":">>)),
{continue, State} = euneus:decode_stream_start(<<"{\"foo\":">>),
?assertEqual(
{end_of_input, #{<<"foo">> => 1}}, euneus:decode_stream_continue(<<"1}">>, State)
).

% Wrapper to suppress dialyzer errors.
% See notes in euneus_decoder_SUITE:stream_continue_state/1.
stream_continue_state({continue, State}) ->
State.

minify_test(Config) when is_list(Config) ->
?assertEqual(
<<"{\"foo\":\"bar\",\"0\":0,[null,true,false,0.001,\"foo\",{\"foo\":0.0001]}">>,
Expand Down
16 changes: 2 additions & 14 deletions test/euneus_decoder_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ stream_start_test(Config) when is_list(Config) ->
].

stream_continue_test(Config) when is_list(Config) ->
State1 = stream_continue_state(euneus_decoder:stream_start(<<"{\"foo\":">>, #{})),
State2 = stream_continue_state(euneus_decoder:stream_start(<<"123">>, #{})),
{continue, State1} = euneus_decoder:stream_start(<<"{\"foo\":">>, #{}),
{continue, State2} = euneus_decoder:stream_start(<<"123">>, #{}),
[
?assertMatch({continue, _}, euneus_decoder:stream_continue(<<"1">>, State1)),
?assertEqual(
Expand All @@ -69,18 +69,6 @@ stream_continue_test(Config) when is_list(Config) ->
?assertEqual({end_of_input, 123}, euneus_decoder:stream_continue(<<>>, State2))
].

% Wrapper to suppress dialyzer errors:
% ```
% test/euneus_decoder_SUITE.erl
% Line 60 Column 1: Function stream_continue_test/1 has no local return
% Line 64 Column 10: The created fun has no local return
% Line 64 Column 77: The call euneus_decoder:stream_continue(<<49>>,
% State1::json:continuation_state()) contains an opaque term as 2nd argument
% when terms of different types are expected in these positions
% '''
stream_continue_state({continue, State}) ->
State.

codecs_test(Config) when is_list(Config) ->
[
?assertEqual([], decode(<<"[]">>, #{codecs => []})),
Expand Down

0 comments on commit 2baa937

Please sign in to comment.