forked from yorickpeterse/ruby-lint
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new version of Rlint::Analyze::Definitions is now capable of building a list of defined modules and their associated data. Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
- Loading branch information
Yorick Peterse
committed
Nov 1, 2012
1 parent
602fe56
commit c6281e0
Showing
3 changed files
with
101 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require File.expand_path('../../../../helper', __FILE__) | ||
|
||
describe 'Rlint::Analyze::Definitions: modules' do | ||
it 'Define a module in the global scope' do | ||
code = <<-CODE | ||
module Example | ||
def example_method | ||
end | ||
end | ||
CODE | ||
|
||
tokens = Rlint::Parser.new(code).parse | ||
iterator = Rlint::Iterator.new | ||
|
||
iterator.bind(Rlint::Analyze::Definitions) | ||
iterator.run(tokens) | ||
|
||
scope = iterator.storage[:scope] | ||
const = scope.lookup(:constant, 'Example') | ||
|
||
const.class.should == Rlint::Definition | ||
|
||
const.token.class.should == Rlint::Token::Token | ||
const.token.type.should == :module | ||
const.token.name.should == ['Example'] | ||
|
||
scope.lookup(:instance_method, 'example_method').nil?.should == true | ||
|
||
method = const.scope.lookup(:instance_method, 'example_method') | ||
|
||
method.class.should == Rlint::Definition | ||
|
||
method.token.class.should == Rlint::Token::MethodDefinitionToken | ||
method.token.name.should == 'example_method' | ||
end | ||
|
||
it 'Define a class method in a module' do | ||
code = <<-CODE | ||
module Example | ||
def self.example_method | ||
end | ||
end | ||
CODE | ||
|
||
tokens = Rlint::Parser.new(code).parse | ||
iterator = Rlint::Iterator.new | ||
|
||
iterator.bind(Rlint::Analyze::Definitions) | ||
iterator.run(tokens) | ||
|
||
scope = iterator.storage[:scope] | ||
const = scope.lookup(:constant, 'Example') | ||
|
||
const.class.should == Rlint::Definition | ||
|
||
const.token.class.should == Rlint::Token::Token | ||
const.token.type.should == :module | ||
const.token.name.should == ['Example'] | ||
|
||
scope.lookup(:method, 'example_method').nil?.should == true | ||
|
||
method = const.scope.lookup(:method, 'example_method') | ||
|
||
method.class.should == Rlint::Definition | ||
|
||
method.token.class.should == Rlint::Token::MethodDefinitionToken | ||
method.token.name.should == 'example_method' | ||
end | ||
end |