summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-10-06 20:10:09 +0900
committergit <svn-admin@ruby-lang.org>2024-10-06 11:10:12 +0000
commit98620f6c5246d27fed440b8d61cdb31cd915eafa (patch)
tree5710416c6e8402d7774c630dbfbdbd1449521ec9 /test
parenta6383fbe1628bdaa9ec6a30b3baa60dd7430b461 (diff)
[ruby/irb] Change default completor from regexp to auto, try
TypeCompletor and fallback to RegexpCompletor. (https://github.com/ruby/irb/pull/1010) https://github.com/ruby/irb/commit/bb6a99d815
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_context.rb2
-rw-r--r--test/irb/test_init.rb10
-rw-r--r--test/irb/test_type_completor.rb16
3 files changed, 25 insertions, 3 deletions
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index 7ad8fd2fc4..9fa23cccef 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -705,6 +705,8 @@ module TestIRB
def test_build_completor
verbose, $VERBOSE = $VERBOSE, nil
original_completor = IRB.conf[:COMPLETOR]
+ IRB.conf[:COMPLETOR] = nil
+ assert_match /IRB::(Regexp|Type)Completor/, @context.send(:build_completor).class.name
IRB.conf[:COMPLETOR] = :regexp
assert_equal 'IRB::RegexpCompletor', @context.send(:build_completor).class.name
IRB.conf[:COMPLETOR] = :unknown
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index 3e8d01c5ce..f7168e02fe 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -167,9 +167,10 @@ module TestIRB
orig_use_autocomplete_env = ENV['IRB_COMPLETOR']
orig_use_autocomplete_conf = IRB.conf[:COMPLETOR]
+ # Default value is nil: auto-detect
ENV['IRB_COMPLETOR'] = nil
IRB.setup(__FILE__)
- assert_equal(:regexp, IRB.conf[:COMPLETOR])
+ assert_equal(nil, IRB.conf[:COMPLETOR])
ENV['IRB_COMPLETOR'] = 'regexp'
IRB.setup(__FILE__)
@@ -193,10 +194,12 @@ module TestIRB
def test_completor_setup_with_argv
orig_completor_conf = IRB.conf[:COMPLETOR]
+ orig_completor_env = ENV['IRB_COMPLETOR']
+ ENV['IRB_COMPLETOR'] = nil
- # Default is :regexp
+ # Default value is nil: auto-detect
IRB.setup(__FILE__, argv: [])
- assert_equal :regexp, IRB.conf[:COMPLETOR]
+ assert_equal nil, IRB.conf[:COMPLETOR]
IRB.setup(__FILE__, argv: ['--type-completor'])
assert_equal :type, IRB.conf[:COMPLETOR]
@@ -205,6 +208,7 @@ module TestIRB
assert_equal :regexp, IRB.conf[:COMPLETOR]
ensure
IRB.conf[:COMPLETOR] = orig_completor_conf
+ ENV['IRB_COMPLETOR'] = orig_completor_env
end
def test_noscript
diff --git a/test/irb/test_type_completor.rb b/test/irb/test_type_completor.rb
index 412d7c696d..3d0e25d19e 100644
--- a/test/irb/test_type_completor.rb
+++ b/test/irb/test_type_completor.rb
@@ -27,6 +27,22 @@ module TestIRB
binding
end
+ def test_build_completor
+ IRB.init_config(nil)
+ verbose, $VERBOSE = $VERBOSE, nil
+ original_completor = IRB.conf[:COMPLETOR]
+ workspace = IRB::WorkSpace.new(Object.new)
+ @context = IRB::Context.new(nil, workspace, TestInputMethod.new)
+ IRB.conf[:COMPLETOR] = nil
+ expected_default_completor = RUBY_VERSION >= '3.4' ? 'IRB::TypeCompletor' : 'IRB::RegexpCompletor'
+ assert_equal expected_default_completor, @context.send(:build_completor).class.name
+ IRB.conf[:COMPLETOR] = :type
+ assert_equal 'IRB::TypeCompletor', @context.send(:build_completor).class.name
+ ensure
+ $VERBOSE = verbose
+ IRB.conf[:COMPLETOR] = original_completor
+ end
+
def assert_completion(preposing, target, binding: empty_binding, include: nil, exclude: nil)
raise ArgumentError if include.nil? && exclude.nil?
candidates = @completor.completion_candidates(preposing, target, '', bind: binding)