summaryrefslogtreecommitdiff
path: root/test/error_highlight
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2023-01-13 17:02:24 +0900
committergit <svn-admin@ruby-lang.org>2023-01-13 08:25:09 +0000
commit94d6d6d93fa40b5f8dcdda6aa0e4b300ee61085c (patch)
treea4a2152fc2da21060e6ef76929c4af03f7284622 /test/error_highlight
parent5b36fefc4e7d0bbaf714fd230c409193d544bcfc (diff)
downloadruby-94d6d6d93fa40b5f8dcdda6aa0e4b300ee61085c.tar.gz
[ruby/error_highlight] Identify which node in `Foo::Bar::Baz` causes a NameError
In Ruby 3.2 or later, a nested constant access like `Foo::Bar::Baz` is compiled to one instruction by the optimization https://github.com/ruby/ruby/pull/6187 We try to spot which sub-node caues a NameError in question based on the constant name. We will give up if the same constant name is accessed in a nested access (`Foo::Foo`). Fixes https://github.com/ruby/error_highlight/pull/31 https://github.com/ruby/error_highlight/commit/0a4db7da0a
Diffstat (limited to 'test/error_highlight')
-rw-r--r--test/error_highlight/test_error_highlight.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb
index 37026d0578..47c7a3dd00 100644
--- a/test/error_highlight/test_error_highlight.rb
+++ b/test/error_highlight/test_error_highlight.rb
@@ -818,6 +818,54 @@ uninitialized constant ErrorHighlightTest::NotDefined
end
end
+ def test_COLON2_3
+ assert_error_message(NameError, <<~END) do
+uninitialized constant ErrorHighlightTest::NotDefined
+
+ ErrorHighlightTest::NotDefined::Foo
+ ^^^^^^^^^^^^
+ END
+
+ ErrorHighlightTest::NotDefined::Foo
+ end
+ end
+
+ def test_COLON2_4
+ assert_error_message(NameError, <<~END) do
+uninitialized constant ErrorHighlightTest::NotDefined
+
+ ::ErrorHighlightTest::NotDefined::Foo
+ ^^^^^^^^^^^^
+ END
+
+ ::ErrorHighlightTest::NotDefined::Foo
+ end
+ end
+
+ if ErrorHighlight.const_get(:Spotter).const_get(:OPT_GETCONSTANT_PATH)
+ def test_COLON2_5
+ # Unfortunately, we cannot identify which `NotDefined` caused the NameError
+ assert_error_message(NameError, <<~END) do
+uninitialized constant ErrorHighlightTest::NotDefined
+ END
+
+ ErrorHighlightTest::NotDefined::NotDefined
+ end
+ end
+ else
+ def test_COLON2_5
+ assert_error_message(NameError, <<~END) do
+uninitialized constant ErrorHighlightTest::NotDefined
+
+ ErrorHighlightTest::NotDefined::NotDefined
+ ^^^^^^^^^^^^
+ END
+
+ ErrorHighlightTest::NotDefined::NotDefined
+ end
+ end
+ end
+
def test_COLON3
assert_error_message(NameError, <<~END) do
uninitialized constant NotDefined