1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

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).
This commit is contained in:
Mon ouïe 2013-01-14 13:36:57 +01:00
parent dac10c6437
commit 2fe52d6e75
2 changed files with 16 additions and 13 deletions

View file

@ -72,10 +72,10 @@ class Pry
path, input = build_path(input) path, input = build_path(input)
unless path.call.empty? 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 target = target.last
end end
begin begin
bind = target bind = target
@ -126,7 +126,7 @@ class Pry
candidates = Object.constants.collect(&:to_s) candidates = Object.constants.collect(&:to_s)
candidates.grep(/^#{receiver}/).collect{|e| "::" + e} candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
# Complete target symbols # Complete target symbols
when /^([A-Z][A-Za-z0-9]*)$/ when /^([A-Z][A-Za-z0-9]*)$/
@ -142,7 +142,7 @@ class Pry
end end
candidates = candidates.grep(/^#{message}/).collect(&path) candidates = candidates.grep(/^#{message}/).collect(&path)
when /^([A-Z].*)::([^:.]*)$/ when /^([A-Z].*)::([^:.]*)$/
# Constant or class methods # Constant or class methods
receiver = $1 receiver = $1
message = Regexp.quote($2) message = Regexp.quote($2)
@ -191,7 +191,7 @@ class Pry
regmessage = Regexp.new(Regexp.quote($1)) regmessage = Regexp.new(Regexp.quote($1))
candidates = global_variables.collect(&:to_s).grep(regmessage) candidates = global_variables.collect(&:to_s).grep(regmessage)
when /^([^."].*)\.([^.]*)$/ when /^([^."].*)\.([^.]*)$/
# Variable # Variable
receiver = $1 receiver = $1
message = Regexp.quote($2) message = Regexp.quote($2)
@ -260,7 +260,7 @@ class Pry
end end
def self.select_message(path, receiver, message, candidates) def self.select_message(path, receiver, message, candidates)
candidates.grep(/^#{message}/).collect do |e| candidates.grep(/^#{message}/).collect { |e|
case e case e
when /^[a-zA-Z_]/ when /^[a-zA-Z_]/
path.call(receiver + "." + e) path.call(receiver + "." + e)
@ -268,12 +268,12 @@ class Pry
when *Operators when *Operators
#receiver + " " + e #receiver + " " + e
end end
end }.compact
end end
# build_path seperates the input into two parts: path and input. # build_path seperates the input into two parts: path and input.
# input is the partial string that should be completed # 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) def self.build_path(input)
# check to see if the input is a regex # check to see if the input is a regex
@ -293,4 +293,3 @@ class Pry
end end
end end
end end

View file

@ -87,10 +87,10 @@ describe Pry::InputCompleter do
# Array # Array
completer_test(o).call('[1].push') completer_test(o).call('[1].push')
# Hash # Hash
completer_test(o).call('{"a" => "b"}.keys') completer_test(o).call('{"a" => "b"}.keys')
# Proc # Proc
completer_test(o).call('{2}.call') completer_test(o).call('{2}.call')
@ -160,10 +160,10 @@ describe Pry::InputCompleter do
# Array # Array
completer_test(o).call('[1].push') completer_test(o).call('[1].push')
# Hash # Hash
completer_test(o).call('{"a" => "b"}.keys') completer_test(o).call('{"a" => "b"}.keys')
# Proc # Proc
completer_test(o).call('{2}.call') completer_test(o).call('{2}.call')
@ -226,4 +226,8 @@ describe Pry::InputCompleter do
completer_test(b, pry).call('/Con') completer_test(b, pry).call('/Con')
end 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 end