ruby-changes:73914
From: st0012 <ko1@a...>
Date: Sat, 8 Oct 2022 03:17:58 +0900 (JST)
Subject: [ruby-changes:73914] 83a9b91522 (master): [ruby/irb] Add tests for primitive types' method completion
https://git.ruby-lang.org/ruby.git/commit/?id=83a9b91522 From 83a9b91522469d5d58e280391138f43afba110af Mon Sep 17 00:00:00 2001 From: st0012 <stan001212@g...> Date: Thu, 6 Oct 2022 11:49:51 +0100 Subject: [ruby/irb] Add tests for primitive types' method completion https://github.com/ruby/irb/commit/2e12fac38e --- test/irb/test_completion.rb | 64 +++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index 8d7476b8f5..35c17b2307 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -27,9 +27,54 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L27 end end - def test_complete_numeric - assert_include(IRB::InputCompletor.retrieve_completion_data("1r.positi", bind: binding), "1r.positive?") - assert_empty(IRB::InputCompletor.retrieve_completion_data("1i.positi", bind: binding)) + class TestMethodCompletion < TestCompletion + def test_complete_string + assert_include(IRB::InputCompletor.retrieve_completion_data("'foo'.up", bind: binding), "'foo'.upcase") + assert_equal(IRB::InputCompletor.retrieve_completion_data("'foo'.upcase", bind: binding, doc_namespace: true), "String.upcase") + end + + def test_complete_regexp + assert_include(IRB::InputCompletor.retrieve_completion_data("/foo/.ma", bind: binding), "/foo/.match") + assert_equal(IRB::InputCompletor.retrieve_completion_data("/foo/.match", bind: binding, doc_namespace: true), "Regexp.match") + end + + def test_complete_array + assert_include(IRB::InputCompletor.retrieve_completion_data("[].an", bind: binding), "[].any?") + assert_equal(IRB::InputCompletor.retrieve_completion_data("[].any?", bind: binding, doc_namespace: true), "Array.any?") + end + + def test_complete_hash_and_proc + # hash + assert_include(IRB::InputCompletor.retrieve_completion_data("{}.an", bind: binding), "{}.any?") + assert_include(IRB::InputCompletor.retrieve_completion_data("{}.any?", bind: binding, doc_namespace: true), "Proc.any?", "Hash.any?") + + # proc + assert_include(IRB::InputCompletor.retrieve_completion_data("{}.bin", bind: binding), "{}.binding") + assert_include(IRB::InputCompletor.retrieve_completion_data("{}.binding", bind: binding, doc_namespace: true), "Proc.binding", "Hash.binding") + end + + def test_complete_numeric + assert_include(IRB::InputCompletor.retrieve_completion_data("1.positi", bind: binding), "1.positive?") + assert_equal(IRB::InputCompletor.retrieve_completion_data("1.positive?", bind: binding, doc_namespace: true), "Integer.positive?") + + assert_include(IRB::InputCompletor.retrieve_completion_data("1r.positi", bind: binding), "1r.positive?") + assert_equal(IRB::InputCompletor.retrieve_completion_data("1r.positive?", bind: binding, doc_namespace: true), "Rational.positive?") + + assert_include(IRB::InputCompletor.retrieve_completion_data("0xFFFF.positi", bind: binding), "0xFFFF.positive?") + assert_equal(IRB::InputCompletor.retrieve_completion_data("0xFFFF.positive?", bind: binding, doc_namespace: true), "Integer.positive?") + + assert_empty(IRB::InputCompletor.retrieve_completion_data("1i.positi", bind: binding)) + end + + def test_complete_symbol + assert_include(IRB::InputCompletor.retrieve_completion_data(":foo.to_p", bind: binding), ":foo.to_proc") + assert_equal(IRB::InputCompletor.retrieve_completion_data(":foo.to_proc", bind: binding, doc_namespace: true), "Symbol.to_proc") + end + + def test_complete_class + assert_include(IRB::InputCompletor.retrieve_completion_data("String.ne", bind: binding), "String.new") + assert_equal(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding, doc_namespace: true), "String.new") + end end def test_complete_symbol @@ -70,14 +115,6 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L115 end end - def test_complete_predicate? - candidates = IRB::InputCompletor.retrieve_completion_data("1.posi", bind: binding) - assert_include candidates, '1.positive?' - - namespace = IRB::InputCompletor.retrieve_completion_data("1.positive?", bind: binding, doc_namespace: true) - assert_equal "Integer.positive?", namespace - end - def test_complete_require candidates = IRB::InputCompletor::CompletionProc.("'irb", "require ", "") %w['irb/init 'irb/ruby-lex].each do |word| @@ -204,11 +241,6 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L241 assert_include(IRB::InputCompletor.retrieve_completion_data("private_hoge", bind: bind, doc_namespace: true), "private_hoge") end - def test_complete_class_method - assert_include(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding), "String.new") - assert_equal(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding, doc_namespace: true), "String.new") - end - def test_complete_sort_variables xzy, xzy_1, xzy2 = '', '', '' -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/