summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreksperimental <eksperimental@users.noreply.github.com>2015-09-27 18:53:05 +0700
committereksperimental <eksperimental@users.noreply.github.com>2015-09-27 18:53:05 +0700
commit0ce1c441d548d670eaa1bb79c974d7c1ea0f9e65 (patch)
treec909037c470c48a7fffdf6595d251c3b991d22d3
parent7ba752e0381d24361347d2071527a2e6874d97ee (diff)
downloadelixir-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.ex6
-rw-r--r--lib/elixir/test/elixir/macro_test.exs5
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)"