File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -1621,18 +1621,27 @@ defmodule Code.Formatter do
1621
1621
byte_size ( digits ) >= 6 ->
1622
1622
digits
1623
1623
|> String . to_charlist ( )
1624
- |> Enum . reverse ( )
1625
- |> Enum . chunk_every ( 3 )
1626
- |> Enum . intersperse ( ~c" _" )
1627
- |> List . flatten ( )
1628
- |> Enum . reverse ( )
1624
+ |> insert_underscores_charlist ( )
1629
1625
|> List . to_string ( )
1630
1626
1631
1627
true ->
1632
1628
digits
1633
1629
end
1634
1630
end
1635
1631
1632
+ defp insert_underscores_charlist ( [ ?- | rest ] ) do
1633
+ [ ?- | insert_underscores_charlist ( rest ) ]
1634
+ end
1635
+
1636
+ defp insert_underscores_charlist ( digits ) do
1637
+ digits
1638
+ |> Enum . reverse ( )
1639
+ |> Enum . chunk_every ( 3 )
1640
+ |> Enum . intersperse ( ~c" _" )
1641
+ |> List . flatten ( )
1642
+ |> Enum . reverse ( )
1643
+ end
1644
+
1636
1645
defp escape_heredoc ( string , escape ) do
1637
1646
string = String . replace ( string , escape , "\\ " <> escape )
1638
1647
heredoc_to_algebra ( [ "" | String . split ( string , "\n " ) ] )
Original file line number Diff line number Diff line change @@ -429,6 +429,16 @@ defmodule MacroTest do
429
429
test "converts quoted to string" do
430
430
assert Macro . to_string ( quote do: hello ( world ) ) == "hello(world)"
431
431
end
432
+
433
+ test "large number literals" do
434
+ # with quote
435
+ assert Macro . to_string ( quote do: 576_460_752_303_423_455 ) == "576_460_752_303_423_455"
436
+ assert Macro . to_string ( quote do: - 576_460_752_303_423_455 ) == "-576_460_752_303_423_455"
437
+
438
+ # without quote
439
+ assert Macro . to_string ( 576_460_752_303_423_455 ) == "576_460_752_303_423_455"
440
+ assert Macro . to_string ( - 576_460_752_303_423_455 ) == "-576_460_752_303_423_455"
441
+ end
432
442
end
433
443
434
444
describe "to_string/2" do
You can’t perform that action at this time.
0 commit comments