diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-11-20 21:43:13 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-11-21 02:43:18 +0000 |
commit | 5299b4a362c000f13778a04acfcac5ec0cd33654 (patch) | |
tree | a40e088ad235938f6030885a27b93ac5d667961d /test/prism/errors_test.rb | |
parent | 9fa524dd41be60654e8515f9e406f6f47f0ac7fa (diff) | |
download | ruby-5299b4a362c000f13778a04acfcac5ec0cd33654.tar.gz |
[ruby/prism] Build the ability to format errors
(https://github.com/ruby/prism/pull/1796)
Previously, we only supported error messages that were constant
strings. This works for the most part, but there are some times
where we want to include some part of the source in the error
message to make it better.
For example, instead of "Token is reserved" it's better to write
"_1 is reserved".
To do this, we now support allocating error messages at runtime
that are built around format strings.
https://github.com/ruby/prism/commit/7e6aa17deb
Diffstat (limited to 'test/prism/errors_test.rb')
-rw-r--r-- | test/prism/errors_test.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index c6ef417e55..c6d35baed4 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -563,15 +563,15 @@ module Prism end RUBY assert_errors expected, source, [ - ["Token reserved for a numbered parameter", 8..10], - ["Token reserved for a numbered parameter", 14..16], - ["Token reserved for a numbered parameter", 20..22], - ["Token reserved for a numbered parameter", 26..28], - ["Token reserved for a numbered parameter", 32..34], - ["Token reserved for a numbered parameter", 40..42], - ["Token reserved for a numbered parameter", 46..48], - ["Token reserved for a numbered parameter", 52..54], - ["Token reserved for a numbered parameter", 58..60], + ["_1 is reserved for a numbered parameter", 8..10], + ["_2 is reserved for a numbered parameter", 14..16], + ["_3 is reserved for a numbered parameter", 20..22], + ["_4 is reserved for a numbered parameter", 26..28], + ["_5 is reserved for a numbered parameter", 32..34], + ["_6 is reserved for a numbered parameter", 40..42], + ["_7 is reserved for a numbered parameter", 46..48], + ["_8 is reserved for a numbered parameter", 52..54], + ["_9 is reserved for a numbered parameter", 58..60], ] end @@ -1253,18 +1253,18 @@ module Prism def test_writing_numbered_parameter assert_errors expression("-> { _1 = 0 }"), "-> { _1 = 0 }", [ - ["Token reserved for a numbered parameter", 5..7] + ["_1 is reserved for a numbered parameter", 5..7] ] end def test_targeting_numbered_parameter assert_errors expression("-> { _1, = 0 }"), "-> { _1, = 0 }", [ - ["Token reserved for a numbered parameter", 5..7] + ["_1 is reserved for a numbered parameter", 5..7] ] end def test_defining_numbered_parameter - error_messages = ["Token reserved for a numbered parameter"] + error_messages = ["_1 is reserved for a numbered parameter"] assert_error_messages "def _1; end", error_messages assert_error_messages "def self._1; end", error_messages @@ -1319,7 +1319,7 @@ module Prism def test_numbered_parameters_in_block_arguments source = "foo { |_1| }" assert_errors expression(source), source, [ - ["Token reserved for a numbered parameter", 7..9], + ["_1 is reserved for a numbered parameter", 7..9], ] end @@ -1405,7 +1405,7 @@ module Prism /(?<_1>)/ =~ a RUBY - message = "Token reserved for a numbered parameter" + message = "_1 is reserved for a numbered parameter" assert_errors expression(source), source, [ [message, 5..7], [message, 13..15], |