2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2010-04-01 03:45:16 -04:00
|
|
|
require File.expand_path '../xref_test_case', __FILE__
|
|
|
|
|
|
|
|
class TestRDocTopLevel < XrefTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@top_level = @store.add_file 'path/top_level.rb'
|
|
|
|
@top_level.parser = RDoc::Parser::Ruby
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
def test_initialize
|
|
|
|
t = RDoc::TopLevel.new 'path/file.rb'
|
|
|
|
|
|
|
|
assert_equal 'path/file.rb', t.absolute_name
|
|
|
|
assert_equal 'path/file.rb', t.relative_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_relative
|
|
|
|
t = RDoc::TopLevel.new 'path/file.rb', 'file.rb'
|
|
|
|
|
|
|
|
assert_equal 'path/file.rb', t.absolute_name
|
|
|
|
assert_equal 'file.rb', t.relative_name
|
|
|
|
end
|
|
|
|
|
2011-06-29 17:17:31 -04:00
|
|
|
def test_add_alias
|
|
|
|
a = RDoc::Alias.new nil, 'old', 'new', nil
|
|
|
|
@top_level.add_alias a
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named 'Object'
|
2011-06-29 17:17:31 -04:00
|
|
|
expected = { '#old' => [a] }
|
|
|
|
assert_equal expected, object.unmatched_alias_lists
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_alias_nodoc
|
|
|
|
@top_level.document_self = false
|
|
|
|
|
|
|
|
a = RDoc::Alias.new nil, 'old', 'new', nil
|
|
|
|
@top_level.add_alias a
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named('Object')
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_empty object.unmatched_alias_lists
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_constant
|
|
|
|
const = RDoc::Constant.new 'C', nil, nil
|
|
|
|
@top_level.add_constant const
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named 'Object'
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_equal [const], object.constants
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_constant_nodoc
|
|
|
|
@top_level.document_self = false
|
|
|
|
|
|
|
|
const = RDoc::Constant.new 'C', nil, nil
|
|
|
|
@top_level.add_constant const
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named 'Object'
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_empty object.constants
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_include
|
|
|
|
include = RDoc::Include.new 'C', nil
|
|
|
|
@top_level.add_include include
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named 'Object'
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_equal [include], object.includes
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_include_nodoc
|
|
|
|
@top_level.document_self = false
|
|
|
|
|
|
|
|
include = RDoc::Include.new 'C', nil
|
|
|
|
@top_level.add_include include
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named('Object')
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_empty object.includes
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_method
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
@top_level.add_method method
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named 'Object'
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_equal [method], object.method_list
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_method_stopdoc
|
|
|
|
@top_level.document_self = false
|
|
|
|
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
@top_level.add_method method
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
object = @store.find_class_named('Object')
|
2011-06-29 17:17:31 -04:00
|
|
|
assert_empty object.method_list
|
|
|
|
assert_includes object.in_files, @top_level
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_base_name
|
|
|
|
assert_equal 'top_level.rb', @top_level.base_name
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_display_eh
|
|
|
|
refute @top_level.display?
|
|
|
|
|
|
|
|
page = @store.add_file 'README.txt'
|
|
|
|
page.parser = RDoc::Parser::Simple
|
|
|
|
|
|
|
|
assert page.display?
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_eql_eh
|
2012-11-26 23:28:14 -05:00
|
|
|
top_level2 = @store.add_file 'path/top_level.rb'
|
|
|
|
other_level = @store.add_file 'path/other_level.rb'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_operator @top_level, :eql?, top_level2
|
|
|
|
|
|
|
|
refute_operator other_level, :eql?, @top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_equals2
|
2012-11-26 23:28:14 -05:00
|
|
|
top_level2 = @store.add_file 'path/top_level.rb'
|
|
|
|
other_level = @store.add_file 'path/other_level.rb'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_equal @top_level, top_level2
|
|
|
|
|
|
|
|
refute_equal other_level, @top_level
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_find_class_or_module
|
|
|
|
assert_equal @c1, @xref_data.find_class_or_module('C1')
|
|
|
|
assert_equal @c2_c3, @xref_data.find_class_or_module('C2::C3')
|
|
|
|
assert_equal @c4, @xref_data.find_class_or_module('C4')
|
|
|
|
assert_equal @m1_m2, @xref_data.find_class_or_module('M1::M2')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_full_name
|
|
|
|
assert_equal 'path/top_level.rb', @top_level.full_name
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_hash
|
2012-11-26 23:28:14 -05:00
|
|
|
tl2 = @store.add_file 'path/top_level.rb'
|
|
|
|
tl3 = @store.add_file 'other/top_level.rb'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_equal @top_level.hash, tl2.hash
|
|
|
|
refute_equal @top_level.hash, tl3.hash
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_http_url
|
|
|
|
assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_last_modified
|
2010-12-19 22:22:49 -05:00
|
|
|
assert_equal nil, @top_level.last_modified
|
2010-04-01 03:45:16 -04:00
|
|
|
stat = Object.new
|
|
|
|
def stat.mtime() 0 end
|
|
|
|
@top_level.file_stat = stat
|
2010-12-19 22:22:49 -05:00
|
|
|
assert_equal 0, @top_level.last_modified
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_marshal_dump
|
|
|
|
page = @store.add_file 'README.txt'
|
|
|
|
page.parser = RDoc::Parser::Simple
|
|
|
|
page.comment = RDoc::Comment.new 'This is a page', page
|
|
|
|
|
|
|
|
loaded = Marshal.load Marshal.dump page
|
|
|
|
|
|
|
|
comment = RDoc::Markup::Document.new(
|
|
|
|
RDoc::Markup::Paragraph.new('This is a page'))
|
|
|
|
comment.file = loaded
|
|
|
|
|
|
|
|
assert_equal page, loaded
|
|
|
|
|
|
|
|
assert_equal 'README.txt', loaded.absolute_name
|
|
|
|
assert_equal 'README.txt', loaded.relative_name
|
|
|
|
|
|
|
|
assert_equal RDoc::Parser::Simple, loaded.parser
|
|
|
|
|
|
|
|
assert_equal comment, loaded.comment
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_marshal_load_version_0
|
|
|
|
loaded = Marshal.load "\x04\bU:\x13RDoc::TopLevel" +
|
|
|
|
"[\ti\x00I\"\x0FREADME.txt\x06:\x06EF" +
|
|
|
|
"c\x19RDoc::Parser::Simple" +
|
|
|
|
"o:\eRDoc::Markup::Document\a:\v@parts" +
|
|
|
|
"[\x06o:\x1CRDoc::Markup::Paragraph\x06;\b" +
|
|
|
|
"[\x06I\"\x13This is a page\x06;\x06F:\n@file@\a"
|
|
|
|
|
|
|
|
comment = RDoc::Markup::Document.new(
|
|
|
|
RDoc::Markup::Paragraph.new('This is a page'))
|
|
|
|
comment.file = loaded
|
|
|
|
|
|
|
|
assert_equal 'README.txt', loaded.absolute_name
|
|
|
|
assert_equal 'README.txt', loaded.relative_name
|
|
|
|
|
|
|
|
assert_equal RDoc::Parser::Simple, loaded.parser
|
|
|
|
|
|
|
|
assert_equal comment, loaded.comment
|
2013-01-22 20:02:24 -05:00
|
|
|
|
|
|
|
assert loaded.display?
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_name
|
|
|
|
assert_equal 'top_level.rb', @top_level.name
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_page_name
|
|
|
|
assert_equal 'top_level', @top_level.page_name
|
|
|
|
|
2013-01-14 17:43:21 -05:00
|
|
|
tl = @store.add_file 'README.ja'
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
assert_equal 'README.ja', tl.page_name
|
|
|
|
|
|
|
|
tl = @store.add_file 'Rakefile'
|
|
|
|
|
|
|
|
assert_equal 'Rakefile', tl.page_name
|
|
|
|
end
|
|
|
|
|
2013-01-14 17:43:21 -05:00
|
|
|
def test_page_name_trim_extension
|
|
|
|
tl = @store.add_file 'README.ja.rdoc'
|
|
|
|
|
|
|
|
assert_equal 'README.ja', tl.page_name
|
|
|
|
|
|
|
|
tl = @store.add_file 'README.ja.md'
|
|
|
|
|
|
|
|
assert_equal 'README.ja', tl.page_name
|
|
|
|
|
|
|
|
tl = @store.add_file 'README.txt'
|
|
|
|
|
|
|
|
assert_equal 'README', tl.page_name
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_search_record
|
|
|
|
assert_nil @xref_data.search_record
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_record_page
|
|
|
|
page = @store.add_file 'README.txt'
|
|
|
|
page.parser = RDoc::Parser::Simple
|
|
|
|
page.comment = 'This is a comment.'
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
'README',
|
|
|
|
'',
|
|
|
|
'README',
|
|
|
|
'',
|
|
|
|
'README_txt.html',
|
|
|
|
'',
|
|
|
|
"<p>This is a comment.\n",
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, page.search_record
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_text_eh
|
|
|
|
refute @xref_data.text?
|
|
|
|
|
|
|
|
rd = @store.add_file 'rd_format.rd'
|
|
|
|
rd.parser = RDoc::Parser::RD
|
|
|
|
|
|
|
|
assert rd.text?
|
|
|
|
|
|
|
|
simple = @store.add_file 'simple.txt'
|
|
|
|
simple.parser = RDoc::Parser::Simple
|
|
|
|
|
|
|
|
assert simple.text?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_text_eh_no_parser
|
|
|
|
refute @xref_data.text?
|
|
|
|
|
|
|
|
rd = @store.add_file 'rd_format.rd'
|
|
|
|
|
|
|
|
refute rd.text?
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|