summaryrefslogtreecommitdiff
path: root/test/irb/test_completion.rb
diff options
context:
space:
mode:
authorosyo-manga <manga.osyo@gmail.com>2022-10-03 06:55:50 +0900
committergit <svn-admin@ruby-lang.org>2022-10-03 06:55:53 +0900
commit7b88ffb34fc995d7499fd9ed384cf7f5ba12994e (patch)
tree978215ccc2627ea5a5a5d45f946749b132a096f1 /test/irb/test_completion.rb
parent5cab9d0ee2b728fe7c76ba303335d3b60bcb00b6 (diff)
[ruby/irb] Change to explicit method call in completion (https://github.com/ruby/irb/pull/369)
Ensure that methods are called even when local variables are defined. see: https://github.com/ruby/irb/issues/368 https://github.com/ruby/irb/commit/c34d54b8bb
Diffstat (limited to 'test/irb/test_completion.rb')
-rw-r--r--test/irb/test_completion.rb47
1 files changed, 46 insertions, 1 deletions
diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb
index a3349bc049..fb10870820 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -152,11 +152,56 @@ module TestIRB
end
def test_complete_variable
+ # Bug fix issues https://github.com/ruby/irb/issues/368
+ # Variables other than `str_example` and `@str_example` are defined to ensure that irb completion does not cause unintended behavior
str_example = ''
- str_example.clear # suppress "assigned but unused variable" warning
+ @str_example = ''
+ private_methods = ''
+ methods = ''
+ global_variables = ''
+ local_variables = ''
+ instance_variables = ''
+
+ # suppress "assigned but unused variable" warning
+ str_example.clear
+ @str_example.clear
+ private_methods.clear
+ methods.clear
+ global_variables.clear
+ local_variables.clear
+ instance_variables.clear
+
assert_include(IRB::InputCompletor.retrieve_completion_data("str_examp", bind: binding), "str_example")
assert_equal(IRB::InputCompletor.retrieve_completion_data("str_example", bind: binding, doc_namespace: true), "String")
assert_equal(IRB::InputCompletor.retrieve_completion_data("str_example.to_s", bind: binding, doc_namespace: true), "String.to_s")
+
+ assert_include(IRB::InputCompletor.retrieve_completion_data("@str_examp", bind: binding), "@str_example")
+ assert_equal(IRB::InputCompletor.retrieve_completion_data("@str_example", bind: binding, doc_namespace: true), "String")
+ assert_equal(IRB::InputCompletor.retrieve_completion_data("@str_example.to_s", bind: binding, doc_namespace: true), "String.to_s")
+ end
+
+ def test_complete_methods
+ obj = Object.new
+ obj.singleton_class.class_eval {
+ def public_hoge; end
+ private def private_hoge; end
+
+ # Support for overriding #methods etc.
+ def methods; end
+ def private_methods; end
+ def global_variables; end
+ def local_variables; end
+ def instance_variables; end
+ }
+ bind = obj.instance_exec { binding }
+
+ assert_include(IRB::InputCompletor.retrieve_completion_data("public_hog", bind: bind), "public_hoge")
+ assert_include(IRB::InputCompletor.retrieve_completion_data("public_hoge.to_s", bind: bind), "public_hoge.to_s")
+ assert_include(IRB::InputCompletor.retrieve_completion_data("public_hoge", bind: bind, doc_namespace: true), "public_hoge")
+
+ assert_include(IRB::InputCompletor.retrieve_completion_data("private_hog", bind: bind), "private_hoge")
+ assert_include(IRB::InputCompletor.retrieve_completion_data("private_hoge.to_s", bind: bind), "private_hoge.to_s")
+ assert_include(IRB::InputCompletor.retrieve_completion_data("private_hoge", bind: bind, doc_namespace: true), "private_hoge")
end
def test_complete_class_method