forked from adamsanderson/ruby_diff
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some tests for the StructureProcessor.
- Loading branch information
1 parent
aeb90aa
commit df8c86f
Showing
2 changed files
with
81 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require 'test/unit' | ||
require 'test/unit/testcase' | ||
require File.expand_path(File.dirname(__FILE__) + "/../ruby_diff") | ||
|
||
class StructureProcessorTestCase < Test::Unit::TestCase | ||
def setup | ||
|
||
end | ||
|
||
def test_instance_method | ||
assert_signatures <<-CODE, ["A#method_1"] | ||
class A | ||
def method_1 | ||
end | ||
end | ||
CODE | ||
end | ||
|
||
def test_instance_method_with_module | ||
assert_signatures <<-CODE, ["B::A#method_1"] | ||
module B | ||
class A | ||
def method_1 | ||
end | ||
end | ||
end | ||
CODE | ||
end | ||
|
||
def test_unscoped_method | ||
assert_signatures <<-CODE, ["#method_1"] | ||
def method_1 | ||
end | ||
CODE | ||
end | ||
|
||
def test_class_method_self | ||
assert_signatures <<-CODE, ["A.method_1"] | ||
class A | ||
def self.method_1 | ||
end | ||
end | ||
CODE | ||
end | ||
|
||
def test_class_method_self_explicit | ||
assert_signatures <<-CODE, ["A.method_1"] | ||
class A | ||
def A.method_1 | ||
end | ||
end | ||
CODE | ||
end | ||
|
||
def test_class_method_append_self | ||
assert_signatures <<-CODE, ["A.method_1"] | ||
class A | ||
class << self | ||
def method_1 | ||
end | ||
end | ||
end | ||
CODE | ||
end | ||
|
||
def assert_signatures(code, signatures) | ||
sexp = ParseTree.new.parse_tree_for_string(code) | ||
processor = StructureProcessor.new() | ||
processor.process(* sexp) | ||
|
||
found_signatures = processor.found_methods.keys.map{|key| key.to_s }.sort | ||
assert_equal signatures.sort, found_signatures | ||
end | ||
|
||
end |