module_candidate.rb improved class lookup regex
Bug prevented lookup of Deeply::Nested::Class::Definitions. Also properly differentiate when looking up docs/source for *commands* and for the class that represents the command, i.e: show-doc show-source #=> displays show-source --help show-doc Pry::Command::ShowSource #=> comments above class definition (as with any other class)
This commit is contained in:
parent
c1ae63446f
commit
92c345aa12
|
@ -78,7 +78,8 @@ class Pry
|
|||
|
||||
return nil if !file.is_a?(String)
|
||||
|
||||
class_regexes = [/^\s*#{mod_type_string}\s*(\w*)(::)?#{wrapped.name.split(/::/).last}/,
|
||||
|
||||
class_regexes = [/^\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped.name.split(/::/).last}/,
|
||||
/^\s*(::)?#{wrapped.name.split(/::/).last}\s*?=\s*?#{wrapped.class}/,
|
||||
/^\s*(::)?#{wrapped.name.split(/::/).last}\.(class|instance)_eval/]
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ describe Pry::CodeObject do
|
|||
@p = Pry.new
|
||||
end
|
||||
|
||||
it 'works' do
|
||||
it 'should return command class' do
|
||||
@p.commands.command "jeremy-jones" do
|
||||
"lobster"
|
||||
end
|
||||
|
@ -52,6 +52,38 @@ describe Pry::CodeObject do
|
|||
m.source.should =~ /lobster/
|
||||
end
|
||||
|
||||
describe "class commands" do
|
||||
before do
|
||||
class LobsterLady < Pry::ClassCommand
|
||||
match "lobster-lady"
|
||||
description "nada."
|
||||
def process
|
||||
"lobster"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
Object.remove_const(:LobsterLady)
|
||||
end
|
||||
|
||||
it 'should return Pry::ClassCommand class when looking up class command' do
|
||||
Pry.commands.add_command(LobsterLady)
|
||||
m = Pry::CodeObject.lookup("lobster-lady", binding, @p)
|
||||
(m <= Pry::ClassCommand).should == true
|
||||
m.source.should =~ /class LobsterLady/
|
||||
Pry.commands.delete("lobster-lady")
|
||||
end
|
||||
|
||||
it 'should return Pry::WrappedModule when looking up command class directly (as a class, not as a command)' do
|
||||
Pry.commands.add_command(LobsterLady)
|
||||
m = Pry::CodeObject.lookup("LobsterLady", binding, @p)
|
||||
m.is_a?(Pry::WrappedModule).should == true
|
||||
m.source.should =~ /class LobsterLady/
|
||||
Pry.commands.delete("lobster-lady")
|
||||
end
|
||||
end
|
||||
|
||||
it 'looks up commands by :listing name as well' do
|
||||
@p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
||||
"lobster"
|
||||
|
@ -215,7 +247,7 @@ describe Pry::CodeObject do
|
|||
o.is_a?(Pry::WrappedModule).should == true
|
||||
end
|
||||
|
||||
# actually locals are never looked up (via co.other_object) when they're classes, it
|
||||
# actually locals are never looked up (via co.default_lookup) when they're classes, it
|
||||
# just falls through to co.method_or_class
|
||||
it 'should look up classes before locals' do
|
||||
c = ClassyWassy
|
||||
|
|
|
@ -335,6 +335,35 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|||
@set.command "command with spaces", "description of a command with spaces" do; end
|
||||
pry_eval('show-doc command with spaces').should =~ /description of a command with spaces/
|
||||
end
|
||||
|
||||
describe "class commands" do
|
||||
before do
|
||||
# cute pink pincers
|
||||
class LobsterLady < Pry::ClassCommand
|
||||
match "lobster-lady"
|
||||
description "nada."
|
||||
def process
|
||||
"lobster"
|
||||
end
|
||||
end
|
||||
|
||||
Pry.commands.add_command(LobsterLady)
|
||||
end
|
||||
|
||||
after do
|
||||
Object.remove_const(:LobsterLady)
|
||||
end
|
||||
|
||||
it 'should display "help" when looking up by command name' do
|
||||
pry_eval('show-doc lobster-lady').should =~ /nada/
|
||||
Pry.commands.delete("lobster-lady")
|
||||
end
|
||||
|
||||
it 'should display actual preceding comment for a class command, when class is used (rather than command name) when looking up' do
|
||||
pry_eval('show-doc LobsterLady').should =~ /cute pink pincers/
|
||||
Pry.commands.delete("lobster-lady")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "should set _file_ and _dir_" do
|
||||
|
|
|
@ -23,6 +23,13 @@ describe Pry::WrappedModule do
|
|||
end
|
||||
|
||||
class ForeverAlone
|
||||
class DoublyNested
|
||||
# nested docs
|
||||
class TriplyNested
|
||||
def nested_method
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -83,6 +90,11 @@ describe Pry::WrappedModule do
|
|||
it 'should return source for third ranked candidate' do
|
||||
Pry::WrappedModule(Host::CandidateTest).candidate(2).source.should =~ /test6/
|
||||
end
|
||||
|
||||
it 'should return source for deeply nested class' do
|
||||
Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.should =~ /nested_method/
|
||||
Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count.should == 4
|
||||
end
|
||||
end
|
||||
|
||||
describe "doc" do
|
||||
|
@ -102,6 +114,10 @@ describe Pry::WrappedModule do
|
|||
it 'should return doc for third ranked candidate' do
|
||||
Pry::WrappedModule(Host::CandidateTest).candidate(2).doc.should =~ /rank 2/
|
||||
end
|
||||
|
||||
it 'should return source for deeply nested class' do
|
||||
Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).doc.should =~ /nested docs/
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
Loading…
Reference in New Issue