From 2fe52d6e7515538734cfd93fce7c5c95f828f62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mon=20ou=C3=AFe?= Date: Mon, 14 Jan 2013 13:36:57 +0100 Subject: [PATCH] Made sure completions proc do not return nil The completion proc returning nil causes errors in input systems that only expect strings (e.g. Coolline). --- lib/pry/completion.rb | 17 ++++++++--------- spec/completion_spec.rb | 12 ++++++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/pry/completion.rb b/lib/pry/completion.rb index 1e681c8d..897f1512 100644 --- a/lib/pry/completion.rb +++ b/lib/pry/completion.rb @@ -72,10 +72,10 @@ class Pry path, input = build_path(input) unless path.call.empty? - target, _ = Pry::Helpers::BaseHelpers.context_from_object_path(path.call, pry) + target, _ = Pry::Helpers::BaseHelpers.context_from_object_path(path.call, pry) target = target.last end - + begin bind = target @@ -126,7 +126,7 @@ class Pry candidates = Object.constants.collect(&:to_s) candidates.grep(/^#{receiver}/).collect{|e| "::" + e} - + # Complete target symbols when /^([A-Z][A-Za-z0-9]*)$/ @@ -142,7 +142,7 @@ class Pry end candidates = candidates.grep(/^#{message}/).collect(&path) - when /^([A-Z].*)::([^:.]*)$/ + when /^([A-Z].*)::([^:.]*)$/ # Constant or class methods receiver = $1 message = Regexp.quote($2) @@ -191,7 +191,7 @@ class Pry regmessage = Regexp.new(Regexp.quote($1)) candidates = global_variables.collect(&:to_s).grep(regmessage) - when /^([^."].*)\.([^.]*)$/ + when /^([^."].*)\.([^.]*)$/ # Variable receiver = $1 message = Regexp.quote($2) @@ -260,7 +260,7 @@ class Pry end def self.select_message(path, receiver, message, candidates) - candidates.grep(/^#{message}/).collect do |e| + candidates.grep(/^#{message}/).collect { |e| case e when /^[a-zA-Z_]/ path.call(receiver + "." + e) @@ -268,12 +268,12 @@ class Pry when *Operators #receiver + " " + e end - end + }.compact end # build_path seperates the input into two parts: path and input. # input is the partial string that should be completed - # path is a proc that takes an input and builds a full path. + # path is a proc that takes an input and builds a full path. def self.build_path(input) # check to see if the input is a regex @@ -293,4 +293,3 @@ class Pry end end end - diff --git a/spec/completion_spec.rb b/spec/completion_spec.rb index 39a933a0..646ec59a 100644 --- a/spec/completion_spec.rb +++ b/spec/completion_spec.rb @@ -87,10 +87,10 @@ describe Pry::InputCompleter do # Array completer_test(o).call('[1].push') - + # Hash completer_test(o).call('{"a" => "b"}.keys') - + # Proc completer_test(o).call('{2}.call') @@ -160,10 +160,10 @@ describe Pry::InputCompleter do # Array completer_test(o).call('[1].push') - + # Hash completer_test(o).call('{"a" => "b"}.keys') - + # Proc completer_test(o).call('{2}.call') @@ -226,4 +226,8 @@ describe Pry::InputCompleter do completer_test(b, pry).call('/Con') end + it 'should not return nil in its output' do + pry = Pry.new + new_completer(binding, pry).call("pry.").should.not.include nil + end end