2010-04-01 03:45:16 -04:00
|
|
|
require 'rubygems'
|
|
|
|
require 'minitest/autorun'
|
|
|
|
require 'rdoc/rdoc'
|
2010-12-19 22:22:49 -05:00
|
|
|
require 'rdoc/generator/ri'
|
2010-04-01 03:45:16 -04:00
|
|
|
require 'tmpdir'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
class TestRDocGeneratorRI < MiniTest::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
2010-12-19 22:22:49 -05:00
|
|
|
@options = RDoc::Options.new
|
2011-06-16 00:59:24 -04:00
|
|
|
@options.encoding = Encoding::UTF_8 if Object.const_defined? :Encoding
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@pwd = Dir.pwd
|
|
|
|
RDoc::TopLevel.reset
|
|
|
|
|
|
|
|
@tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_ri_#{$$}"
|
|
|
|
FileUtils.mkdir_p @tmpdir
|
|
|
|
Dir.chdir @tmpdir
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
@g = RDoc::Generator::RI.new @options
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
@top_level = RDoc::TopLevel.new 'file.rb'
|
|
|
|
@klass = @top_level.add_class RDoc::NormalClass, 'Object'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@meth = RDoc::AnyMethod.new nil, 'method'
|
2011-06-16 00:59:24 -04:00
|
|
|
@meth.record_location @top_level
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@meth_bang = RDoc::AnyMethod.new nil, 'method!'
|
2011-06-16 00:59:24 -04:00
|
|
|
@meth_bang.record_location @top_level
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@attr = RDoc::Attr.new nil, 'attr', 'RW', ''
|
2011-06-16 00:59:24 -04:00
|
|
|
@attr.record_location @top_level
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
@klass.add_method @meth
|
|
|
|
@klass.add_method @meth_bang
|
|
|
|
@klass.add_attribute @attr
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Dir.chdir @pwd
|
|
|
|
FileUtils.rm_rf @tmpdir
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_file path
|
|
|
|
assert File.file?(path), "#{path} is not a file"
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def refute_file path
|
|
|
|
refute File.exist?(path), "#{path} exists"
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_generate
|
|
|
|
@g.generate nil
|
|
|
|
|
|
|
|
assert_file File.join(@tmpdir, 'cache.ri')
|
|
|
|
|
|
|
|
assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')
|
|
|
|
|
|
|
|
assert_file File.join(@tmpdir, 'Object', 'attr-i.ri')
|
|
|
|
assert_file File.join(@tmpdir, 'Object', 'method-i.ri')
|
|
|
|
assert_file File.join(@tmpdir, 'Object', 'method%21-i.ri')
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
store = RDoc::RI::Store.new @tmpdir
|
|
|
|
store.load_cache
|
|
|
|
|
|
|
|
encoding = Object.const_defined?(:Encoding) ? Encoding::UTF_8 : nil
|
|
|
|
|
|
|
|
assert_equal encoding, store.encoding
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_generate_dry_run
|
|
|
|
@options.dry_run = true
|
|
|
|
@g = RDoc::Generator::RI.new @options
|
|
|
|
|
|
|
|
top_level = RDoc::TopLevel.new 'file.rb'
|
|
|
|
top_level.add_class @klass.class, @klass.name
|
|
|
|
|
|
|
|
@g.generate nil
|
|
|
|
|
|
|
|
refute_file File.join(@tmpdir, 'cache.ri')
|
|
|
|
|
|
|
|
refute_file File.join(@tmpdir, 'Object')
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|