diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 470903b451..4df285ce64 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -76,7 +76,7 @@ module IRB # :nodoc: @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod) @CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty? @CONF[:USE_AUTOCOMPLETE] = ENV.fetch("IRB_USE_AUTOCOMPLETE", "true") != "false" - @CONF[:COMPLETOR] = :regexp + @CONF[:COMPLETOR] = ENV.fetch("IRB_COMPLETOR", "regexp").to_sym @CONF[:INSPECT_MODE] = true @CONF[:USE_TRACER] = false @CONF[:USE_LOADER] = false diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index e330cc5e84..b6a8f5529b 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -120,6 +120,34 @@ module TestIRB IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf end + def test_completor_environment_variable + orig_use_autocomplete_env = ENV['IRB_COMPLETOR'] + orig_use_autocomplete_conf = IRB.conf[:COMPLETOR] + + ENV['IRB_COMPLETOR'] = nil + IRB.setup(__FILE__) + assert_equal(:regexp, IRB.conf[:COMPLETOR]) + + ENV['IRB_COMPLETOR'] = 'regexp' + IRB.setup(__FILE__) + assert_equal(:regexp, IRB.conf[:COMPLETOR]) + + ENV['IRB_COMPLETOR'] = 'type' + IRB.setup(__FILE__) + assert_equal(:type, IRB.conf[:COMPLETOR]) + + ENV['IRB_COMPLETOR'] = 'regexp' + IRB.setup(__FILE__, argv: ['--type-completor']) + assert_equal :type, IRB.conf[:COMPLETOR] + + ENV['IRB_COMPLETOR'] = 'type' + IRB.setup(__FILE__, argv: ['--regexp-completor']) + assert_equal :regexp, IRB.conf[:COMPLETOR] + ensure + ENV['IRB_COMPLETOR'] = orig_use_autocomplete_env + IRB.conf[:COMPLETOR] = orig_use_autocomplete_conf + end + def test_completor_setup_with_argv orig_completor_conf = IRB.conf[:COMPLETOR]