Skip to content

Commit

Permalink
Try solve duplicated json modules
Browse files Browse the repository at this point in the history
  • Loading branch information
williamthome committed Aug 4, 2024
1 parent bd7c80a commit 5d6326a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

strategy:
matrix:
otp-version: [24, 25, 26, 27]
otp-version: [25, 26, 27]
os: [ubuntu-24.04]

steps:
Expand Down Expand Up @@ -55,7 +55,13 @@ jobs:
-rebar3-${{steps.setup-beam.outputs.rebar3-version}}\
-hash-${{hashFiles('rebar.lock')}}"

- name: Continuous Integration (Polyfill)
if: ${{matrix.otp-version != '27'}}
run: |
rebar3 as test polyfill_ci
- name: Continuous Integration
if: ${{matrix.otp-version == '27'}}
run: |
rebar3 as test ci
Expand Down
11 changes: 10 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
{plt_extra_apps, [
common_test,
eunit,
json_polyfill,
doctest,
jiffy,
thoas
Expand Down Expand Up @@ -118,6 +117,16 @@
ct,
{cover, "--min_coverage 100"},
ex_doc
]},
{polyfill_ci, [
{fmt, "--check"},
lint,
hank,
xref,
eunit,
ct,
{cover, "--min_coverage 100"},
ex_doc
]}
]}.

Expand Down
2 changes: 2 additions & 0 deletions src/euneus_encoder.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@

-ifdef(TEST).
-include_lib("doctest/include/doctest.hrl").
% TODO: Remove this.
-doctest(false).
-endif.

%% --------------------------------------------------------------------
Expand Down
44 changes: 44 additions & 0 deletions test/euneus_encoder_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
-include_lib("stdlib/include/assert.hrl").
-compile([export_all, nowarn_export_all]).

%

-elvis([{elvis_style, dont_repeat_yourself, disable}]).

%% --------------------------------------------------------------------
%% Behaviour (ct_suite) callbacks
%% --------------------------------------------------------------------
Expand Down Expand Up @@ -132,6 +136,7 @@ skip_values_test(Config) when is_list(Config) ->
)
].

-if(?OTP_RELEASE >= 26).
key_to_binary_test(Config) when is_list(Config) ->
[
?assertEqual(
Expand All @@ -148,6 +153,24 @@ key_to_binary_test(Config) when is_list(Config) ->
encode(#{foo => world}, #{key_to_binary => fun(_) -> <<"hello">> end})
)
].
-else.
key_to_binary_test(Config) when is_list(Config) ->
[
?assertEqual(
<<"{\"foo\":\"foo\",\"baz\":\"baz\",\"bar\":\"bar\",\"0\":0}">>,
encode(#{
<<"foo">> => foo,
bar => bar,
"baz" => baz,
0 => 0
})
),
?assertEqual(
<<"{\"hello\":\"world\"}">>,
encode(#{foo => world}, #{key_to_binary => fun(_) -> <<"hello">> end})
)
].
-endif.

sort_keys_test(Config) when is_list(Config) ->
[
Expand All @@ -158,6 +181,7 @@ sort_keys_test(Config) when is_list(Config) ->
)
].

-if(?OTP_RELEASE >= 26).
proplists_test(Config) when is_list(Config) ->
[
?assertEqual(<<"[]">>, encode([], #{proplists => true})),
Expand All @@ -176,6 +200,26 @@ proplists_test(Config) when is_list(Config) ->
})
)
].
-else.
proplists_test(Config) when is_list(Config) ->
[
?assertEqual(<<"[]">>, encode([], #{proplists => true})),
?assertEqual(
<<"[null,{\"foo\":\"bar\",\"baz\":true,\"0\":0}]">>,
encode([null, [{foo, bar}, baz, {0, 0}]], #{proplists => true})
),
?assertEqual(
<<"[null,{\"foo\":\"bar\"}]">>,
encode([null, [{foo, bar}]], #{
proplists =>
{true, fun
([{_, _}]) -> true;
(_) -> false
end}
})
)
].
-endif.

escape_test(Config) when is_list(Config) ->
?assertEqual(<<"bar">>, encode(foo, #{escape => fun(_) -> <<"bar">> end})).
Expand Down

0 comments on commit 5d6326a

Please sign in to comment.