Skip to content

Commit 5fbdee2

Browse files
eksperimentaljosevalim
authored andcommitted
Quote range operator atom
This commit has only the actual changes Add tests for quoted range operator
1 parent 832fbce commit 5fbdee2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ defmodule Code.Formatter do
553553
if keyword_key?(left_arg) do
554554
{left, state} =
555555
case left_arg do
556+
# TODO: Remove this clause in v1.16 when we no longer quote operator :..//
557+
{:__block__, _, [:"..//"]} ->
558+
{string(~S{"..//":}), state}
559+
556560
{:__block__, _, [atom]} when is_atom(atom) ->
557561
key =
558562
case Code.Identifier.classify(atom) do
@@ -1533,6 +1537,11 @@ defmodule Code.Formatter do
15331537
Atom.to_string(atom)
15341538
end
15351539

1540+
# TODO: Remove this clause in v1.16 when we no longer quote operator :..//
1541+
defp atom_to_algebra(:"..//") do
1542+
string(":\"..//\"")
1543+
end
1544+
15361545
defp atom_to_algebra(atom) do
15371546
string = Atom.to_string(atom)
15381547

lib/elixir/test/elixir/code_formatter/literals_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ defmodule Code.Formatter.LiteralsTest do
107107
assert_format ~S[:"++"], ~S[:++]
108108
end
109109

110+
test "quoted operators" do
111+
assert_same ~S[:"::"]
112+
assert_same ~S[:"..//"]
113+
assert_format ~S[:..//], ~S[:"..//"]
114+
assert_format ~S{[..//: 1]}, ~S{["..//": 1]}
115+
assert_same ~S{["..//": 1]}
116+
end
117+
110118
test "uses double quotes even when single quotes are used" do
111119
assert_format ~S[:'foo bar'], ~S[:"foo bar"]
112120
end

0 commit comments

Comments
 (0)