2011-08-17 04:53:20 +00:00
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
describe Pry::InputCompleter do
|
|
|
|
|
|
|
|
before do
|
|
|
|
# The AMQP gem has some classes like this:
|
|
|
|
# pry(main)> AMQP::Protocol::Test::ContentOk.name
|
|
|
|
# => :content_ok
|
|
|
|
module SymbolyName
|
|
|
|
def self.name; :symboly_name; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.remove_const :SymbolyName
|
|
|
|
end
|
|
|
|
|
2011-09-06 17:20:04 +00:00
|
|
|
# another jruby hack :((
|
2011-12-27 22:38:25 +00:00
|
|
|
if !Pry::Helpers::BaseHelpers.jruby?
|
2011-09-06 17:20:04 +00:00
|
|
|
it "should not crash if there's a Module that has a symbolic name." do
|
|
|
|
completer = Pry::InputCompleter.build_completion_proc(Pry.binding_for(Object.new))
|
|
|
|
lambda{ completer.call "a.to_s." }.should.not.raise Exception
|
|
|
|
end
|
2011-08-17 04:53:20 +00:00
|
|
|
end
|
2012-06-19 10:32:03 +00:00
|
|
|
|
2012-06-19 09:40:58 +00:00
|
|
|
it 'should take parenthesis and other characters into account for symbols' do
|
|
|
|
b = Pry.binding_for(Object.new)
|
|
|
|
completer = Pry::InputCompleter.build_completion_proc(b)
|
|
|
|
|
|
|
|
lambda { completer.call(":class)") }.should.not.raise(RegexpError)
|
|
|
|
end
|
2012-06-19 13:47:52 +00:00
|
|
|
|
2012-06-19 10:32:03 +00:00
|
|
|
it 'should complete instance variables' do
|
|
|
|
object = Object.new
|
|
|
|
|
|
|
|
object.instance_variable_set(:'@name', 'Pry')
|
2012-06-19 11:09:55 +00:00
|
|
|
object.class.send(:class_variable_set, :'@@number', 10)
|
2012-06-19 10:32:03 +00:00
|
|
|
|
2012-08-10 02:32:23 +00:00
|
|
|
object.instance_variables.map { |v| v.to_sym } \
|
|
|
|
.include?(:'@name').should == true
|
2012-06-19 10:32:03 +00:00
|
|
|
|
2012-08-10 02:32:23 +00:00
|
|
|
object.class.class_variables.map { |v| v.to_sym } \
|
|
|
|
.include?(:'@@number').should == true
|
|
|
|
|
|
|
|
completer = Pry::InputCompleter.build_completion_proc(
|
|
|
|
Pry.binding_for(object)
|
|
|
|
)
|
2012-06-19 10:32:03 +00:00
|
|
|
|
|
|
|
# Complete instance variables.
|
2012-08-10 02:32:23 +00:00
|
|
|
completer.call('@na').include?('@name').should == true
|
|
|
|
completer.call('@name.down').include?('@name.downcase').should == true
|
2012-06-19 10:32:03 +00:00
|
|
|
|
|
|
|
# Complete class variables.
|
2012-08-10 02:32:23 +00:00
|
|
|
completer = Pry::InputCompleter.build_completion_proc(
|
|
|
|
Pry.binding_for(object.class)
|
|
|
|
)
|
2012-06-19 10:32:03 +00:00
|
|
|
|
2012-08-10 02:32:23 +00:00
|
|
|
completer.call('@@nu').include?('@@number').should == true
|
|
|
|
completer.call('@@number.cl').include?('@@number.class').should == true
|
2012-06-19 10:32:03 +00:00
|
|
|
end
|
2011-08-17 04:53:20 +00:00
|
|
|
end
|
|
|
|
|