Clarify behaviour of Macro.to_string on invalid ASTs

Closes #13875.
This commit is contained in:
José Valim
2024-10-02 08:48:49 +02:00
parent 8dcc969517
commit e2556fd478
4 changed files with 27 additions and 50 deletions
@@ -226,17 +226,6 @@ defmodule Code.Normalizer.QuotedASTTest do
assert quoted_to_string(quoted) <> "\n" == expected
end
test "invalid block" do
assert quoted_to_string({:__block__, [], {:bar, [], []}}) ==
"{:__block__, [], {:bar, [], []}}"
assert quoted_to_string({:foo, [], [{:do, :ok}, :not_keyword]}) ==
"foo({:do, :ok}, :not_keyword)"
assert quoted_to_string({:foo, [], [[{:do, :ok}, :not_keyword]]}) ==
"foo([{:do, :ok}, :not_keyword])"
end
test "not in" do
assert quoted_to_string(quote(do: false not in [])) == "false not in []"
end
@@ -738,6 +727,23 @@ defmodule Code.Normalizer.QuotedASTTest do
end
end
describe "quoted_to_algebra/2 with invalid" do
test "block" do
assert quoted_to_string({:__block__, [], {:bar, [], []}}) ==
"{:__block__, [], {:bar, [], []}}"
assert quoted_to_string({:foo, [], [{:do, :ok}, :not_keyword]}) ==
"foo({:do, :ok}, :not_keyword)"
assert quoted_to_string({:foo, [], [[{:do, :ok}, :not_keyword]]}) ==
"foo([{:do, :ok}, :not_keyword])"
end
test "ode" do
assert quoted_to_string(1..3) == "1..3"
end
end
describe "quoted_to_algebra/2 does not escape" do
test "sigils" do
assert quoted_to_string(quote(do: ~s/a\nb\tc/), escape: false) == ~S"~s/a\nb\tc/"