Skip to content

Commit

Permalink
Add tests for map comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
elbrujohalcon committed Oct 25, 2024
1 parent 97fca07 commit 361bcd2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
4 changes: 3 additions & 1 deletion test/otp_formatter_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ test_app(_Config) ->
"src/ignored_file_config.erl",
"src/dodge_macros.erl",
"src/macros_in_specs.erl",
"src/receive_after.erl"]};
"src/receive_after.erl",
"src/otp26.erl"]};
_ ->
{ignore,
["src/*_ignore.erl",
Expand All @@ -42,6 +43,7 @@ test_app(_Config) ->
"src/dodge_macros.erl",
"src/macros_in_specs.erl",
"src/receive_after.erl",
"src/otp26.erl",
"src/otp25.erl"]}
end,
State2 = rebar_state:set(State1, format, [Files, Formatter, IgnoredFiles]),
Expand Down
13 changes: 10 additions & 3 deletions test/test_app_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ init_test_app() ->
of
{N, _} when N >= 26 ->
%% newlines in strings are treated differently since OTP26
{ignore, ["src/strings/non_heredoc.erl", "src/*_ignore.erl", "src/ignored_file_config.erl"]};
{ignore,
["src/strings/non_heredoc.erl",
"src/*_ignore.erl",
"src/ignored_file_config.erl"]};
{25, _} ->
{ignore, ["src/*_ignore.erl", "src/ignored_file_config.erl"]};
{ignore, ["src/*_ignore.erl", "src/ignored_file_config.erl", "src/otp26.erl"]};
_ ->
{ignore, ["src/*_ignore.erl", "src/ignored_file_config.erl", "src/otp25.erl"]}
{ignore,
["src/*_ignore.erl",
"src/ignored_file_config.erl",
"src/otp26.erl",
"src/otp25.erl"]}
end,
rebar_state:set(State1, format, [Files, IgnoredFiles]).

Expand Down
24 changes: 24 additions & 0 deletions test_app/after/src/otp26.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%% @doc New stuff introduced in OTP26.
-module(otp26).

-export([map_comprehensions/3]).

map_comprehensions(Map, List, Binary) ->
MapFromList = #{{k, Key} => {value, Value} || Key <- List, Value <- List},
MapFromBinary =
#{{k, Key} => {value, Value}
|| <<Key/float>> <- Binary, Key >= 8.24551123345, <<Value/binary>> <- Binary},
MapFromMap =
#{#{key => Key} => [value, Value, is_a_value]
|| {k, Key} := {value, Value} <- MapFromList, is_integer(Key)},
MapFromCombo = #{Key => binary_to_atom(Value) || Key <- List, <<Value/binary>> <= Binary},
ListFromMap =
[{Key, Value}
|| {k, Key} := Value <- MapFromBinary,
with:one_filter(Key),
with:another_filter(Value) == <<"a good value">>],
BinaryFromMap =
<< <<Key:64, $|, Value/binary>>
|| #{key := Key} := [value, Value | _] <- MapFromMap, is_binary(Value) >>,
NoGenerator = #{k => v || this:is_true()},
#{MapFromCombo => ListFromMap, BinaryFromMap => NoGenerator}.
14 changes: 14 additions & 0 deletions test_app/src/otp26.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%% @doc New stuff introduced in OTP26.
-module(otp26).

-export([map_comprehensions/3]).

map_comprehensions(Map, List, Binary) ->
MapFromList = #{ {k, Key} => {value, Value} || Key <- List, Value <- List },
MapFromBinary = #{ {k, Key} => {value, Value} || <<Key/float>> <- Binary, Key >= 8.24551123345, <<Value/binary>> <- Binary},
MapFromMap = #{ #{key => Key} => [value, Value, is_a_value] || {k, Key} := {value, Value} <- MapFromList, is_integer(Key) },
MapFromCombo = #{ Key => binary_to_atom(Value) || Key <- List, <<Value/binary>> <= Binary},
ListFromMap = [{Key, Value} || {k, Key} := Value <- MapFromBinary, with:one_filter(Key), with:another_filter(Value) == <<"a good value">>],
BinaryFromMap = << <<Key:64, $|, Value/binary>> || #{key := Key} := [value, Value | _] <- MapFromMap, is_binary(Value) >>,
NoGenerator = #{k => v || this:is_true()},
#{MapFromCombo => ListFromMap, BinaryFromMap => NoGenerator}.

0 comments on commit 361bcd2

Please sign in to comment.