summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_ri_driver.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rdoc/test_rdoc_ri_driver.rb')
-rw-r--r--test/rdoc/test_rdoc_ri_driver.rb100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb
new file mode 100644
index 0000000000..5db831915a
--- /dev/null
+++ b/test/rdoc/test_rdoc_ri_driver.rb
@@ -0,0 +1,100 @@
+require 'test/unit'
+require 'tmpdir'
+require 'rdoc/ri/driver'
+
+class TestRDocRIDriver < Test::Unit::TestCase
+
+ def setup
+ @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_driver_#{$$}"
+ @home_ri = File.join @tmpdir, 'dot_ri'
+ @cache_dir = File.join @home_ri, 'cache'
+ @class_cache = File.join @cache_dir, 'classes'
+
+ FileUtils.mkdir_p @tmpdir
+ FileUtils.mkdir_p @home_ri
+ FileUtils.mkdir_p @cache_dir
+
+ @driver = RDoc::RI::Driver.new
+ @driver.homepath = @home_ri
+ end
+
+ def teardown
+ FileUtils.rm_rf @tmpdir
+ end
+
+ def test_lookup_method
+ def @driver.load_cache_for(klassname)
+ { 'Foo#bar' => :found }
+ end
+
+ assert @driver.lookup_method('Foo#bar', 'Foo')
+ end
+
+ def test_lookup_method_class_method
+ def @driver.load_cache_for(klassname)
+ { 'Foo::Bar' => :found }
+ end
+
+ assert @driver.lookup_method('Foo::Bar', 'Foo::Bar')
+ end
+
+ def test_lookup_method_class_missing
+ def @driver.load_cache_for(klassname) end
+
+ e = assert_raise RDoc::RI::Driver::NotFoundError do
+ @driver.lookup_method 'Foo#bar', 'Foo'
+ end
+
+ assert_equal 'Nothing known about Foo#bar', e.message
+ end
+
+ def test_lookup_method_dot_instance
+ def @driver.load_cache_for(klassname)
+ { 'Foo#bar' => :instance, 'Foo::bar' => :klass }
+ end
+
+ assert_equal :instance, @driver.lookup_method('Foo.bar', 'Foo')
+ end
+
+ def test_lookup_method_dot_class
+ def @driver.load_cache_for(klassname)
+ { 'Foo::bar' => :found }
+ end
+
+ assert @driver.lookup_method('Foo.bar', 'Foo')
+ end
+
+ def test_lookup_method_method_missing
+ def @driver.load_cache_for(klassname) {} end
+
+ e = assert_raise RDoc::RI::Driver::NotFoundError do
+ @driver.lookup_method 'Foo#bar', 'Foo'
+ end
+
+ assert_equal 'Nothing known about Foo#bar', e.message
+ end
+
+ def test_parse_name
+ klass, meth = @driver.parse_name 'Foo::Bar'
+
+ assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
+ assert_equal nil, meth, 'Foo::Bar method'
+
+ klass, meth = @driver.parse_name 'Foo#Bar'
+
+ assert_equal 'Foo', klass, 'Foo#Bar class'
+ assert_equal 'Bar', meth, 'Foo#Bar method'
+
+ klass, meth = @driver.parse_name 'Foo.Bar'
+
+ assert_equal 'Foo', klass, 'Foo#Bar class'
+ assert_equal 'Bar', meth, 'Foo#Bar method'
+
+ klass, meth = @driver.parse_name 'Foo::bar'
+
+ assert_equal 'Foo', klass, 'Foo::bar class'
+ assert_equal 'bar', meth, 'Foo::bar method'
+ end
+
+end
+