OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / test / rdoc / test_rdoc_ri_driver.rb
1 require 'rubygems'
2 require 'minitest/unit'
3 require 'tmpdir'
4 require 'rdoc/ri/driver'
5
6 class TestRDocRIDriver < MiniTest::Unit::TestCase
7
8   def setup
9     @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_driver_#{$$}"
10     @home_ri = File.join @tmpdir, 'dot_ri'
11     @cache_dir = File.join @home_ri, 'cache'
12     @class_cache = File.join @cache_dir, 'classes'
13
14     FileUtils.mkdir_p @tmpdir
15     FileUtils.mkdir_p @home_ri
16     FileUtils.mkdir_p @cache_dir
17
18     @driver = RDoc::RI::Driver.new(RDoc::RI::Driver.process_args([]))
19     @driver.homepath = @home_ri
20   end
21
22   def teardown
23     FileUtils.rm_rf @tmpdir
24   end
25
26   def test_lookup_method
27     def @driver.load_cache_for(klassname)
28       { 'Foo#bar' => :found }
29     end
30
31     assert @driver.lookup_method('Foo#bar',  'Foo')
32   end
33
34   def test_lookup_method_class_method
35     def @driver.load_cache_for(klassname)
36       { 'Foo::Bar' => :found }
37     end
38
39     assert @driver.lookup_method('Foo::Bar', 'Foo::Bar')
40   end
41
42   def test_lookup_method_class_missing
43     def @driver.load_cache_for(klassname) end
44
45     assert_nil @driver.lookup_method('Foo#bar', 'Foo')
46   end
47
48   def test_lookup_method_dot_instance
49     def @driver.load_cache_for(klassname)
50       { 'Foo#bar' => :instance, 'Foo::bar' => :klass }
51     end
52
53     assert_equal :instance, @driver.lookup_method('Foo.bar', 'Foo')
54   end
55
56   def test_lookup_method_dot_class
57     def @driver.load_cache_for(klassname)
58       { 'Foo::bar' => :found }
59     end
60
61     assert @driver.lookup_method('Foo.bar', 'Foo')
62   end
63
64   def test_lookup_method_method_missing
65     def @driver.load_cache_for(klassname) {} end
66
67     assert_nil @driver.lookup_method('Foo#bar', 'Foo')
68   end
69
70   def test_parse_name
71     klass, meth = @driver.parse_name 'Foo::Bar'
72
73     assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
74     assert_equal nil,        meth,  'Foo::Bar method'
75
76     klass, meth = @driver.parse_name 'Foo#Bar'
77
78     assert_equal 'Foo', klass, 'Foo#Bar class'
79     assert_equal 'Bar', meth,  'Foo#Bar method'
80
81     klass, meth = @driver.parse_name 'Foo.Bar'
82
83     assert_equal 'Foo', klass, 'Foo#Bar class'
84     assert_equal 'Bar', meth,  'Foo#Bar method'
85
86     klass, meth = @driver.parse_name 'Foo::bar'
87
88     assert_equal 'Foo', klass, 'Foo::bar class'
89     assert_equal 'bar', meth,  'Foo::bar method'
90   end
91
92 end
93
94 MiniTest::Unit.autorun