Skip to content

Commit b725b8c

Browse files
doorganjosevalim
authored andcommitted
Set a max line_length for Macro.to_string (#11471)
1 parent 47171d9 commit b725b8c

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

lib/elixir/lib/macro.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ defmodule Macro do
945945
"""
946946
@spec to_string(t()) :: String.t()
947947
def to_string(tree) do
948-
doc = Inspect.Algebra.format(Code.quoted_to_algebra(tree), :infinity)
948+
doc = Inspect.Algebra.format(Code.quoted_to_algebra(tree), 98)
949949
IO.iodata_to_binary(doc)
950950
end
951951

lib/elixir/test/elixir/kernel_test.exs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,12 @@ defmodule KernelTest do
723723
result = expand_to_string(quote(do: rand() in 1..2))
724724
assert result =~ "var = rand()"
725725

726-
assert result =~
727-
":erlang.andalso(:erlang.is_integer(var), :erlang.andalso(:erlang.>=(var, 1), :erlang.\"=<\"(var, 2)))"
726+
assert result =~ """
727+
:erlang.andalso(
728+
:erlang.is_integer(var),
729+
:erlang.andalso(:erlang.>=(var, 1), :erlang.\"=<\"(var, 2))
730+
)\
731+
"""
728732

729733
# Empty list
730734
assert expand_to_string(quote(do: :x in [])) =~ "_ = :x\nfalse"
@@ -754,14 +758,26 @@ defmodule KernelTest do
754758
assert expand_to_string(quote(do: foo in [])) ==
755759
"_ = foo\nfalse"
756760

757-
assert expand_to_string(quote(do: foo in [1, 2, 3])) ==
758-
":erlang.orelse(:erlang.orelse(:erlang.\"=:=\"(foo, 1), :erlang.\"=:=\"(foo, 2)), :erlang.\"=:=\"(foo, 3))"
759-
760-
assert expand_to_string(quote(do: foo in 0..1)) ==
761-
":erlang.andalso(:erlang.is_integer(foo), :erlang.andalso(:erlang.>=(foo, 0), :erlang.\"=<\"(foo, 1)))"
762-
763-
assert expand_to_string(quote(do: foo in -1..0)) ==
764-
":erlang.andalso(:erlang.is_integer(foo), :erlang.andalso(:erlang.>=(foo, -1), :erlang.\"=<\"(foo, 0)))"
761+
assert expand_to_string(quote(do: foo in [1, 2, 3])) == """
762+
:erlang.orelse(
763+
:erlang.orelse(:erlang.\"=:=\"(foo, 1), :erlang.\"=:=\"(foo, 2)),
764+
:erlang.\"=:=\"(foo, 3)
765+
)\
766+
"""
767+
768+
assert expand_to_string(quote(do: foo in 0..1)) == """
769+
:erlang.andalso(
770+
:erlang.is_integer(foo),
771+
:erlang.andalso(:erlang.>=(foo, 0), :erlang.\"=<\"(foo, 1))
772+
)\
773+
"""
774+
775+
assert expand_to_string(quote(do: foo in -1..0)) == """
776+
:erlang.andalso(
777+
:erlang.is_integer(foo),
778+
:erlang.andalso(:erlang.>=(foo, -1), :erlang.\"=<\"(foo, 0))
779+
)\
780+
"""
765781

766782
assert expand_to_string(quote(do: foo in 1..1)) ==
767783
":erlang.\"=:=\"(foo, 1)"

0 commit comments

Comments
 (0)