diff options
author | st0012 <stan001212@gmail.com> | 2022-10-06 11:49:51 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-10-08 03:17:38 +0900 |
commit | 83a9b91522469d5d58e280391138f43afba110af (patch) | |
tree | 8dbc069e2266696978374c330aeefccda28de609 /test/irb | |
parent | d76854f1668fc6ee1cd8af15213d6e225269a9e4 (diff) |
[ruby/irb] Add tests for primitive types' method completion
https://github.com/ruby/irb/commit/2e12fac38e
Diffstat (limited to 'test/irb')
-rw-r--r-- | test/irb/test_completion.rb | 64 |
1 files 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 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 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 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 = '', '', '' |