Skip to content

Commit 9b3df0b

Browse files
committed
lager_trunc_io: clean up unneeded check for erlang:is_map/1
1 parent ecb78c5 commit 9b3df0b

File tree

1 file changed

+54
-68
lines changed

1 file changed

+54
-68
lines changed

‎src/lager_trunc_io.erl‎

Lines changed: 54 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,12 @@ print(List, Max, Options) when is_list(List) ->
279279
{[$[, R, $]], Len + 2}
280280
end;
281281

282-
print(Map, Max, Options) ->
283-
case erlang:is_builtin(erlang, is_map, 1) andalso erlang:is_map(Map) of
284-
true ->
285-
{MapBody, Len} = map_body(Map, Max - 3, dec_depth(Options)),
286-
{[$#, ${, MapBody, $}], Len + 3};
287-
false ->
288-
error(badarg, [Map, Max, Options])
289-
end.
282+
print(Map, Max, Options) when is_map(Map) ->
283+
{MapBody, Len} = map_body(Map, Max - 3, dec_depth(Options)),
284+
{[$#, ${, MapBody, $}], Len + 3};
285+
286+
print(Term, Max, Options) ->
287+
error(badarg, [Term, Max, Options]).
290288

291289
%% Returns {List, Length}
292290
tuple_contents(Tuple, Max, Options) ->
@@ -743,44 +741,39 @@ tuple_printing_test() ->
743741
ok.
744742

745743
map_printing_test() ->
746-
case erlang:is_builtin(erlang, is_map, 1) of
747-
true ->
748-
?assertEqual("#{}", lists:flatten(format("~p", [maps:new()], 50))),
749-
?assertEqual("#{}", lists:flatten(format("~p", [maps:new()], 3))),
750-
?assertEqual("#{}", lists:flatten(format("~w", [maps:new()], 50))),
751-
?assertError(badarg, lists:flatten(format("~s", [maps:new()], 50))),
752-
?assertEqual("#{...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 1))),
753-
?assertEqual("#{...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 6))),
754-
?assertEqual("#{bar => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 7))),
755-
?assertEqual("#{bar => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 9))),
756-
?assertEqual("#{bar => foo}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 10))),
757-
?assertEqual("#{bar => ...,...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 9))),
758-
?assertEqual("#{bar => foo,...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 10))),
759-
?assertEqual("#{bar => foo,...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 17))),
760-
?assertEqual("#{bar => foo,foo => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 18))),
761-
?assertEqual("#{bar => foo,foo => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 19))),
762-
?assertEqual("#{bar => foo,foo => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 20))),
763-
?assertEqual("#{bar => foo,foo => bar}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 21))),
764-
?assertEqual("#{22835963083295358096932575511191922182123945984 => ...}",
765-
lists:flatten(format("~w", [
766-
maps:from_list([{22835963083295358096932575511191922182123945984,
767-
22835963083295358096932575511191922182123945984}])], 10))),
768-
?assertEqual("#{22835963083295358096932575511191922182123945984 => ...}",
769-
lists:flatten(format("~w", [
770-
maps:from_list([{22835963083295358096932575511191922182123945984,
771-
bar}])], 10))),
772-
?assertEqual("#{22835963083295358096932575511191922182123945984 => ...}",
773-
lists:flatten(format("~w", [
774-
maps:from_list([{22835963083295358096932575511191922182123945984,
775-
bar}])], 53))),
776-
?assertEqual("#{22835963083295358096932575511191922182123945984 => bar}",
777-
lists:flatten(format("~w", [
778-
maps:from_list([{22835963083295358096932575511191922182123945984,
779-
bar}])], 54))),
780-
ok;
781-
false ->
782-
ok
783-
end.
744+
?assertEqual("#{}", lists:flatten(format("~p", [maps:new()], 50))),
745+
?assertEqual("#{}", lists:flatten(format("~p", [maps:new()], 3))),
746+
?assertEqual("#{}", lists:flatten(format("~w", [maps:new()], 50))),
747+
?assertError(badarg, lists:flatten(format("~s", [maps:new()], 50))),
748+
?assertEqual("#{...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 1))),
749+
?assertEqual("#{...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 6))),
750+
?assertEqual("#{bar => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 7))),
751+
?assertEqual("#{bar => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 9))),
752+
?assertEqual("#{bar => foo}", lists:flatten(format("~p", [maps:from_list([{bar, foo}])], 10))),
753+
?assertEqual("#{bar => ...,...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 9))),
754+
?assertEqual("#{bar => foo,...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 10))),
755+
?assertEqual("#{bar => foo,...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 17))),
756+
?assertEqual("#{bar => foo,foo => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 18))),
757+
?assertEqual("#{bar => foo,foo => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 19))),
758+
?assertEqual("#{bar => foo,foo => ...}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 20))),
759+
?assertEqual("#{bar => foo,foo => bar}", lists:flatten(format("~p", [maps:from_list([{bar, foo}, {foo, bar}])], 21))),
760+
?assertEqual("#{22835963083295358096932575511191922182123945984 => ...}",
761+
lists:flatten(format("~w", [
762+
maps:from_list([{22835963083295358096932575511191922182123945984,
763+
22835963083295358096932575511191922182123945984}])], 10))),
764+
?assertEqual("#{22835963083295358096932575511191922182123945984 => ...}",
765+
lists:flatten(format("~w", [
766+
maps:from_list([{22835963083295358096932575511191922182123945984,
767+
bar}])], 10))),
768+
?assertEqual("#{22835963083295358096932575511191922182123945984 => ...}",
769+
lists:flatten(format("~w", [
770+
maps:from_list([{22835963083295358096932575511191922182123945984,
771+
bar}])], 53))),
772+
?assertEqual("#{22835963083295358096932575511191922182123945984 => bar}",
773+
lists:flatten(format("~w", [
774+
maps:from_list([{22835963083295358096932575511191922182123945984,
775+
bar}])], 54))),
776+
ok.
784777

785778
unicode_test() ->
786779
?assertEqual([231,167,129], lists:flatten(format("~s", [<<231,167,129>>], 50))),
@@ -805,28 +798,21 @@ depth_limit_test() ->
805798
?assertEqual("{a,{b,{c,{...}}}}", lists:flatten(format("~P", [{a, {b, {c, {d}}}}, 7], 50))),
806799
?assertEqual("{a,{b,{c,{d}}}}", lists:flatten(format("~P", [{a, {b, {c, {d}}}}, 8], 50))),
807800

808-
case erlang:is_builtin(erlang, is_map, 1) of
809-
true ->
810-
?assertEqual("#{a => #{...}}",
811-
lists:flatten(format("~P",
812-
[maps:from_list([{a, maps:from_list([{b, maps:from_list([{c, d}])}])}]), 2], 50))),
813-
?assertEqual("#{a => #{b => #{...}}}",
814-
lists:flatten(format("~P",
815-
[maps:from_list([{a, maps:from_list([{b, maps:from_list([{c, d}])}])}]), 3], 50))),
816-
?assertEqual("#{a => #{b => #{c => d}}}",
817-
lists:flatten(format("~P",
818-
[maps:from_list([{a, maps:from_list([{b, maps:from_list([{c, d}])}])}]), 4], 50))),
819-
820-
?assertEqual("#{}", lists:flatten(format("~P", [maps:new(), 1], 50))),
821-
?assertEqual("#{...}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 1], 50))),
822-
?assertEqual("#{1 => 1,...}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 2], 50))),
823-
?assertEqual("#{1 => 1,2 => 2,...}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 3], 50))),
824-
?assertEqual("#{1 => 1,2 => 2,3 => 3}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 4], 50))),
825-
826-
ok;
827-
false ->
828-
ok
829-
end,
801+
?assertEqual("#{a => #{...}}",
802+
lists:flatten(format("~P",
803+
[maps:from_list([{a, maps:from_list([{b, maps:from_list([{c, d}])}])}]), 2], 50))),
804+
?assertEqual("#{a => #{b => #{...}}}",
805+
lists:flatten(format("~P",
806+
[maps:from_list([{a, maps:from_list([{b, maps:from_list([{c, d}])}])}]), 3], 50))),
807+
?assertEqual("#{a => #{b => #{c => d}}}",
808+
lists:flatten(format("~P",
809+
[maps:from_list([{a, maps:from_list([{b, maps:from_list([{c, d}])}])}]), 4], 50))),
810+
811+
?assertEqual("#{}", lists:flatten(format("~P", [maps:new(), 1], 50))),
812+
?assertEqual("#{...}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 1], 50))),
813+
?assertEqual("#{1 => 1,...}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 2], 50))),
814+
?assertEqual("#{1 => 1,2 => 2,...}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 3], 50))),
815+
?assertEqual("#{1 => 1,2 => 2,3 => 3}", lists:flatten(format("~P", [maps:from_list([{1,1}, {2,2}, {3,3}]), 4], 50))),
830816

831817
?assertEqual("{\"a\",[...]}", lists:flatten(format("~P", [{"a", ["b", ["c", ["d"]]]}, 3], 50))),
832818
?assertEqual("{\"a\",[\"b\",[[...]|...]]}", lists:flatten(format("~P", [{"a", ["b", ["c", ["d"]]]}, 6], 50))),

0 commit comments

Comments
 (0)