summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@dashbit.co>2021-11-26 21:01:00 +0100
committerJosé Valim <jose.valim@dashbit.co>2021-11-26 21:02:07 +0100
commit3b93c6f969ba3dadfbe676445c080e25a3d4161b (patch)
tree5f083a1479120ca89a5b0b9040e59f0294489d8f
parentadab68df21f533a434fc2b4518ab792cf8e6d9fb (diff)
downloadelixir-3b93c6f969ba3dadfbe676445c080e25a3d4161b.tar.gz
Move syntax errors to parser file
-rw-r--r--lib/elixir/test/elixir/kernel/errors_test.exs41
-rw-r--r--lib/elixir/test/elixir/kernel/parser_test.exs51
2 files changed, 50 insertions, 42 deletions
diff --git a/lib/elixir/test/elixir/kernel/errors_test.exs b/lib/elixir/test/elixir/kernel/errors_test.exs
index 94aa18c38..55ceee9c3 100644
--- a/lib/elixir/test/elixir/kernel/errors_test.exs
+++ b/lib/elixir/test/elixir/kernel/errors_test.exs
@@ -215,29 +215,6 @@ defmodule Kernel.ErrorsTest do
'foo = 1; %{put_in(foo.bar.baz, nil), foo}'
end
- test "expression after keyword lists" do
- assert_eval_raise SyntaxError,
- ~r"unexpected expression after keyword list",
- 'call foo: 1, :bar'
-
- assert_eval_raise SyntaxError,
- ~r"unexpected expression after keyword list",
- 'call(foo: 1, :bar)'
-
- assert_eval_raise SyntaxError,
- ~r"unexpected expression after keyword list",
- '[foo: 1, :bar]'
-
- assert_eval_raise SyntaxError,
- ~r"unexpected expression after keyword list",
- '%{foo: 1, :bar => :bar}'
- end
-
- test "syntax errors include formatted snippet" do
- message = "nofile:1:5: syntax error before: '*'\n |\n 1 | 1 + * 3\n | ^"
- assert_eval_raise SyntaxError, message, "1 + * 3"
- end
-
test "struct fields on defstruct" do
assert_eval_raise ArgumentError, "struct field names must be atoms, got: 1", '''
defmodule Kernel.ErrorsTest.StructFieldsOnDefstruct do
@@ -816,24 +793,6 @@ defmodule Kernel.ErrorsTest do
'x = 8; <<a, b::size(^x)>> = <<?a, ?b>>'
end
- test "invalid bidi in source" do
- assert_eval_raise SyntaxError,
- ~r"nofile:1:1: invalid bidirectional formatting character in comment: \\u202A",
- '# This is a \u202A'
-
- assert_eval_raise SyntaxError,
- ~r"nofile:1:5: invalid bidirectional formatting character in comment: \\u202A",
- 'foo. # This is a \u202A'
-
- assert_eval_raise SyntaxError,
- ~r"nofile:1:12: invalid bidirectional formatting character in string: \\u202A. If you want to use such character, use it in its escaped \\u202A form instead",
- '"this is a \u202A"'
-
- assert_eval_raise SyntaxError,
- ~r"nofile:1:13: invalid bidirectional formatting character in string: \\u202A. If you want to use such character, use it in its escaped \\u202A form instead",
- '"this is a \\\u202A"'
- end
-
test "function head with guard" do
assert_eval_raise CompileError, "nofile:2: missing :do option in \"def\"", '''
defmodule Kernel.ErrorsTest.BodyessFunctionWithGuard do
diff --git a/lib/elixir/test/elixir/kernel/parser_test.exs b/lib/elixir/test/elixir/kernel/parser_test.exs
index 9c79c7762..21fef5741 100644
--- a/lib/elixir/test/elixir/kernel/parser_test.exs
+++ b/lib/elixir/test/elixir/kernel/parser_test.exs
@@ -510,6 +510,28 @@ defmodule Kernel.ParserTest do
)
end
+ test "invalid bidi in source" do
+ assert_syntax_error(
+ ~r"nofile:1:1: invalid bidirectional formatting character in comment: \\u202A",
+ '# This is a \u202A'
+ )
+
+ assert_syntax_error(
+ ~r"nofile:1:5: invalid bidirectional formatting character in comment: \\u202A",
+ 'foo. # This is a \u202A'
+ )
+
+ assert_syntax_error(
+ ~r"nofile:1:12: invalid bidirectional formatting character in string: \\u202A. If you want to use such character, use it in its escaped \\u202A form instead",
+ '"this is a \u202A"'
+ )
+
+ assert_syntax_error(
+ ~r"nofile:1:13: invalid bidirectional formatting character in string: \\u202A. If you want to use such character, use it in its escaped \\u202A form instead",
+ '"this is a \\\u202A"'
+ )
+ end
+
test "reserved tokens" do
assert_syntax_error(~r/nofile:1:1: reserved token: __aliases__/, '__aliases__')
assert_syntax_error(~r/nofile:1:1: reserved token: __block__/, '__block__')
@@ -589,7 +611,7 @@ defmodule Kernel.ParserTest do
assert_syntax_error(message, :unicode.characters_to_nfd_list("foó"))
end
- test "kw missing space" do
+ test "keyword missing space" do
msg = ~r/nofile:1:1: keyword argument must be followed by space after: foo:/
assert_syntax_error(msg, "foo:bar")
@@ -597,6 +619,33 @@ defmodule Kernel.ParserTest do
assert_syntax_error(msg, "foo:+1")
end
+ test "expression after keyword lists" do
+ assert_syntax_error(
+ ~r"unexpected expression after keyword list",
+ 'call foo: 1, :bar'
+ )
+
+ assert_syntax_error(
+ ~r"unexpected expression after keyword list",
+ 'call(foo: 1, :bar)'
+ )
+
+ assert_syntax_error(
+ ~r"unexpected expression after keyword list",
+ '[foo: 1, :bar]'
+ )
+
+ assert_syntax_error(
+ ~r"unexpected expression after keyword list",
+ '%{foo: 1, :bar => :bar}'
+ )
+ end
+
+ test "syntax errors include formatted snippet" do
+ message = "nofile:1:5: syntax error before: '*'\n |\n 1 | 1 + * 3\n | ^"
+ assert_syntax_error(message, "1 + * 3")
+ end
+
test "invalid map start" do
assert_syntax_error(
~r/nofile:1:7: expected %{ to define a map, got: %\[/,