diff options
author | eksperimental <eksperimental@users.noreply.github.com> | 2015-09-27 18:53:05 +0700 |
---|---|---|
committer | eksperimental <eksperimental@users.noreply.github.com> | 2015-09-27 18:53:05 +0700 |
commit | 0ce1c441d548d670eaa1bb79c974d7c1ea0f9e65 (patch) | |
tree | c909037c470c48a7fffdf6595d251c3b991d22d3 | |
parent | 7ba752e0381d24361347d2071527a2e6874d97ee (diff) | |
download | elixir-0ce1c441d548d670eaa1bb79c974d7c1ea0f9e65.tar.gz |
Fix Macro.to_string/2 to print ranges
this removes the spaces between the ranges and the periods
-rw-r--r-- | lib/elixir/lib/macro.ex | 6 | ||||
-rw-r--r-- | lib/elixir/test/elixir/macro_test.exs | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index f180ccd15..1ba92b9fd 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -537,6 +537,12 @@ defmodule Macro do fun.(ast, "fn\n " <> block <> "\nend") end + # Ranges + def to_string({:.., _, args} = ast, fun) do + range = Enum.map_join(args, "..", &to_string(&1, fun)) + fun.(ast, range) + end + # left -> right def to_string([{:->, _, _}|_] = ast, fun) do fun.(ast, "(" <> arrow_to_string(ast, fun, true) <> ")") diff --git a/lib/elixir/test/elixir/macro_test.exs b/lib/elixir/test/elixir/macro_test.exs index 3b5396fb4..4c8f1d7d5 100644 --- a/lib/elixir/test/elixir/macro_test.exs +++ b/lib/elixir/test/elixir/macro_test.exs @@ -354,6 +354,11 @@ defmodule MacroTest do """ end + test "range to string" do + assert Macro.to_string(quote do: (1 .. 2)) == "1..2" + assert Macro.to_string(quote do: unquote(-1 .. +2)) == "-1..2" + end + test "when" do assert Macro.to_string(quote do: (() -> x)) == "(() -> x)" assert Macro.to_string(quote do: (x when y -> z)) == "(x when y -> z)" |