diff options
author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-07-01 02:13:22 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-06-30 17:13:27 +0000 |
commit | de2d9c8e22b59ee9be5491c1abe8ab02bee66e84 (patch) | |
tree | 4e1093d38f6bf1ccda6c0f11bc3b2db5cb95b410 /test | |
parent | c4baf3b3c0953c8df24a87db2059f831f45f19ab (diff) | |
download | ruby-de2d9c8e22b59ee9be5491c1abe8ab02bee66e84.tar.gz |
[ruby/irb] Allow assigning and using local variable name conflicting
with command
(https://github.com/ruby/irb/pull/961)
https://github.com/ruby/irb/commit/00603d470f
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/command/test_custom_command.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/irb/command/test_custom_command.rb b/test/irb/command/test_custom_command.rb index 3a3ad11d5a..13f412c210 100644 --- a/test/irb/command/test_custom_command.rb +++ b/test/irb/command/test_custom_command.rb @@ -145,5 +145,50 @@ module TestIRB assert_include(output, "No description provided.") assert_not_include(output, "Maybe IRB bug") end + + def test_command_name_local_variable + write_ruby <<~RUBY + require "irb/command" + + class FooBarCommand < IRB::Command::Base + category 'CommandTest' + description 'test' + def execute(arg) + puts "arg=\#{arg.inspect}" + end + end + + IRB::Command.register(:foo_bar, FooBarCommand) + + binding.irb + RUBY + + output = run_ruby_file do + type "binding.irb" + type "foo_bar == 1 || 1" + type "foo_bar =~ /2/ || 2" + type "exit" + type "binding.irb" + type "foo_bar = '3'; foo_bar" + type "foo_bar == 4 || '4'" + type "foo_bar =~ /5/ || '5'" + type "exit" + type "binding.irb" + type "foo_bar ||= '6'; foo_bar" + type "foo_bar == 7 || '7'" + type "foo_bar =~ /8/ || '8'" + type "exit" + type "exit" + end + + assert_include(output, 'arg="== 1 || 1"') + assert_include(output, 'arg="=~ /2/ || 2"') + assert_include(output, '=> "3"') + assert_include(output, '=> "4"') + assert_include(output, '=> "5"') + assert_include(output, '=> "6"') + assert_include(output, '=> "7"') + assert_include(output, '=> "8"') + end end end |