diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rdoc/test_rdoc_any_method.rb | 63 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_class_module.rb | 6 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_code_object.rb | 40 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_context.rb | 11 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_normal_class.rb | 6 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_normal_module.rb | 6 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_options.rb | 57 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser_c.rb | 187 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser_ruby.rb | 334 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_rdoc.rb | 18 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_ri_driver.rb | 58 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_stats.rb | 507 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_task.rb | 31 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_text.rb | 64 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_top_level.rb | 2 |
15 files changed, 1353 insertions, 37 deletions
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index 2a7ae9042a..2104322c91 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -34,6 +34,12 @@ method(a, b) { |c, d| ... } assert_equal call_seq, m.arglists end + def test_c_function + @c1_m.c_function = 'my_c1_m' + + assert_equal 'my_c1_m', @c1_m.c_function + end + def test_full_name assert_equal 'C1::m', @c1.method_list.first.full_name end @@ -97,6 +103,48 @@ method(a, b) { |c, d| ... } assert_nil m.name end + def test_param_list_block_params + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + m.block_params = 'c, d' + + assert_equal %w[c d], m.param_list + end + + def test_param_list_call_seq + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + call_seq = <<-SEQ +method(a) { |c| ... } +method(a, b) { |c, d| ... } + SEQ + + m.call_seq = call_seq + + assert_equal %w[a b c d], m.param_list + end + + def test_param_list_params + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + m.params = '(a, b)' + + assert_equal %w[a b], m.param_list + end + + def test_param_list_params_block_params + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + m.params = '(a, b)' + m.block_params = 'c, d' + + assert_equal %w[a b c d], m.param_list + end + def test_param_seq m = RDoc::AnyMethod.new nil, 'method' m.parent = @c1 @@ -117,6 +165,21 @@ method(a, b) { |c, d| ... } assert_equal '(a, b) { |c, d| ... }', m.param_seq end + def test_param_seq_call_seq + m = RDoc::AnyMethod.new nil, 'method' + m.parent = @c1 + + call_seq = <<-SEQ +method(a) { |c| ... } +method(a, b) { |c, d| ... } + SEQ + + m.call_seq = call_seq + + assert_equal '(a, b) { |c, d| }', m.param_seq + + end + def test_parent_name assert_equal 'C1', @c1.method_list.first.parent_name assert_equal 'C1', @c1.method_list.last.parent_name diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index aa9bab5ec9..e7a68c2b4c 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -114,7 +114,7 @@ class TestRDocClassModule < XrefTestCase n1 = @xref_data.add_module RDoc::NormalClass, 'N1' n1_k2 = n1.add_module RDoc::NormalClass, 'N2' - n1.add_module_alias n1_k2, 'A1' + n1.add_module_alias n1_k2, 'A1', @xref_data n1_a1_c = n1.constants.find { |c| c.name == 'A1' } refute_nil n1_a1_c @@ -138,7 +138,7 @@ class TestRDocClassModule < XrefTestCase n1 = @xref_data.add_module RDoc::NormalModule, 'N1' n1_n2 = n1.add_module RDoc::NormalModule, 'N2' - n1.add_module_alias n1_n2, 'A1' + n1.add_module_alias n1_n2, 'A1', @xref_data n1_a1_c = n1.constants.find { |c| c.name == 'A1' } refute_nil n1_a1_c @@ -163,7 +163,7 @@ class TestRDocClassModule < XrefTestCase l1_l2 = l1.add_module RDoc::NormalModule, 'L2' o1 = @xref_data.add_module RDoc::NormalModule, 'O1' - o1.add_module_alias l1_l2, 'A1' + o1.add_module_alias l1_l2, 'A1', @xref_data o1_a1_c = o1.constants.find { |c| c.name == 'A1' } refute_nil o1_a1_c diff --git a/test/rdoc/test_rdoc_code_object.rb b/test/rdoc/test_rdoc_code_object.rb index 8ae2d8b91e..5328ab26b1 100644 --- a/test/rdoc/test_rdoc_code_object.rb +++ b/test/rdoc/test_rdoc_code_object.rb @@ -30,6 +30,34 @@ class TestRDocCodeObject < XrefTestCase assert_equal 'I am a comment', @co.comment end + def test_comment_equals_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + refute_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check' + + input = 'text' + input.force_encoding Encoding::UTF_8 + + @co.comment = input + + assert_equal 'text', @co.comment + assert_equal Encoding::UTF_8, @co.comment.encoding + end + + def test_comment_equals_encoding_blank + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + refute_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check' + + input = '' + input.force_encoding Encoding::UTF_8 + + @co.comment = input + + assert_equal '', @co.comment + assert_equal Encoding::UTF_8, @co.comment.encoding + end + def test_document_children_equals @co.document_children = false refute @co.document_children @@ -101,6 +129,12 @@ class TestRDocCodeObject < XrefTestCase assert_nil @co.instance_variable_get(:@full_name) end + def test_line + @c1_m.line = 5 + + assert_equal 5, @c1_m.line + end + def test_metadata assert_empty @co.metadata @@ -113,6 +147,12 @@ class TestRDocCodeObject < XrefTestCase assert_equal 'not_rdoc', @co.metadata['markup'] end + def test_offset + @c1_m.offset = 5 + + assert_equal 5, @c1_m.offset + end + def test_parent_file_name assert_equal '(unknown)', @co.parent_file_name assert_equal 'xref_data.rb', @c1.parent_file_name diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb index 6961f7d214..9f110fc9f8 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -174,9 +174,16 @@ class TestRDocContext < XrefTestCase end def test_add_module_alias - c3_c4 = @c2.add_module_alias @c2_c3, 'C4' + tl = RDoc::TopLevel.new 'file.rb' - assert_equal @c2.find_module_named('C4'), c3_c4 + c3_c4 = @c2.add_module_alias @c2_c3, 'C4', tl + + c4 = @c2.find_module_named('C4') + + alias_constant = @c2.constants.first + + assert_equal c4, c3_c4 + assert_equal tl, alias_constant.file end def test_add_module_class diff --git a/test/rdoc/test_rdoc_normal_class.rb b/test/rdoc/test_rdoc_normal_class.rb index db07ecb9c7..bd0d67e19c 100644 --- a/test/rdoc/test_rdoc_normal_class.rb +++ b/test/rdoc/test_rdoc_normal_class.rb @@ -13,5 +13,11 @@ class TestRDocNormalClass < XrefTestCase assert_equal [incl.name, klass], sub_klass.ancestors end + def test_definition + c = RDoc::NormalClass.new 'C' + + assert_equal 'class C', c.definition + end + end diff --git a/test/rdoc/test_rdoc_normal_module.rb b/test/rdoc/test_rdoc_normal_module.rb index 570b2765c6..975bf911fe 100644 --- a/test/rdoc/test_rdoc_normal_module.rb +++ b/test/rdoc/test_rdoc_normal_module.rb @@ -23,6 +23,12 @@ class TestRDocNormalModule < XrefTestCase assert_equal [mod2, incl.name], mod.ancestors end + def test_definition + m = RDoc::NormalModule.new 'M' + + assert_equal 'module M', m.definition + end + def test_module_eh assert @mod.module? end diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index ec8bd9478d..763f50b5f0 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -17,7 +17,7 @@ class TestRDocOptions < MiniTest::Unit::TestCase end def test_check_files - skip "assumes UNIX permition model" if /mswin|mingw/ =~ RUBY_PLATFORM + skip "assumes UNIX permission model" if /mswin|mingw/ =~ RUBY_PLATFORM out, err = capture_io do Dir.mktmpdir do |dir| Dir.chdir dir do @@ -67,6 +67,25 @@ file 'unreadable' not readable assert_equal expected, @options.generator_descriptions end + def test_parse_coverage + @options.parse %w[--dcov] + + assert @options.coverage_report + assert @options.force_update + end + + def test_parse_coverage_no + @options.parse %w[--no-dcov] + + refute @options.coverage_report + end + + def test_parse_coverage_level_1 + @options.parse %w[--dcov=1] + + assert_equal 1, @options.coverage_report + end + def test_parse_dash_p out, err = capture_io do @options.parse %w[-p] @@ -327,16 +346,46 @@ file 'unreadable' not readable def self.op() @op end end - RDoc::RDoc::GENERATORS['TestGenerator'] = test_generator + RDoc::RDoc::GENERATORS['test'] = test_generator + + @options.setup_generator 'test' + + assert_equal test_generator, @options.generator + assert_equal [test_generator], @options.generator_options + + assert_equal @options, test_generator.op + ensure + RDoc::RDoc::GENERATORS.delete 'test' + end + + def test_setup_generator_no_option_parser + test_generator = Class.new do + def self.setup_options op + op.option_parser.separator nil + @op = op + end + + def self.op() @op end + end + + RDoc::RDoc::GENERATORS['test'] = test_generator - @options.setup_generator 'TestGenerator' + @options.setup_generator 'test' assert_equal test_generator, @options.generator assert_equal [test_generator], @options.generator_options assert_equal @options, test_generator.op ensure - RDoc::RDoc::GENERATORS.delete 'TestGenerator' + RDoc::RDoc::GENERATORS.delete 'test' + end + + def test_update_output_dir + assert @options.update_output_dir + + @options.update_output_dir = false + + refute @options.update_output_dir end end diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index dd856c1bcf..6a3a92001a 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -101,6 +101,7 @@ void Init_Blah(void) { assert_equal 'accessor', accessor.name assert_equal 'RW', accessor.rw assert_equal 'This is an accessor', accessor.comment + assert_equal @top_level, accessor.file reader = attrs.shift assert_equal 'reader', reader.name @@ -134,6 +135,7 @@ void Init_Blah(void) { assert_equal 'accessor', accessor.name assert_equal 'RW', accessor.rw assert_equal 'This is an accessor', accessor.comment + assert_equal @top_level, accessor.file end def test_do_aliases @@ -159,6 +161,9 @@ void Init_Blah(void) { assert_equal 2, methods.length assert_equal 'bleh', methods.last.name assert_equal 'blah', methods.last.is_alias_for.name + + assert_equal @top_level, methods.last.is_alias_for.file + assert_equal @top_level, methods.last.file end def test_do_aliases_singleton @@ -339,6 +344,8 @@ void Init_foo(){ constants = klass.constants assert !klass.constants.empty? + assert_equal @top_level, constants.first.file + constants = constants.map { |c| [c.name, c.value, c.comment] } assert_equal ['PERFECT', '300', 'The highest possible score in bowling '], @@ -529,7 +536,7 @@ Init_Foo(void) { code = other_function.token_stream.first.text - assert_equal "VALUE\nother_function() ", code + assert_equal "VALUE\nother_function() {\n}", code end def test_find_body_2 @@ -574,6 +581,41 @@ init_gi_repository (void) def test_find_body_define content = <<-EOF +#define something something_else + +#define other_function rb_other_function + +/* + * a comment for rb_other_function + */ +VALUE +rb_other_function() { +} + +void +Init_Foo(void) { + VALUE foo = rb_define_class("Foo", rb_cObject); + + rb_define_method(foo, "my_method", other_function, 0); +} + EOF + + klass = util_get_class content, 'foo' + other_function = klass.method_list.first + + assert_equal 'my_method', other_function.name + assert_equal 'a comment for rb_other_function', other_function.comment + assert_equal '()', other_function.params + assert_equal 118, other_function.offset + assert_equal 8, other_function.line + + code = other_function.token_stream.first.text + + assert_equal "VALUE\nrb_other_function() {\n}", code + end + + def test_find_body_define_comment + content = <<-EOF /* * a comment for other_function */ @@ -596,9 +638,10 @@ Init_Foo(void) { other_function = klass.method_list.first assert_equal 'my_method', other_function.name - assert_equal "a comment for other_function", - other_function.comment + assert_equal 'a comment for other_function', other_function.comment assert_equal '()', other_function.params + assert_equal 39, other_function.offset + assert_equal 4, other_function.line code = other_function.token_stream.first.text @@ -742,7 +785,51 @@ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] assert_equal expected, comment end - def test_handle_method + def test_handle_method_args_minus_1 + parser = util_parser "Document-method: Object#m\n blah */" + + parser.content = <<-BODY +VALUE +rb_other(VALUE obj) { + rb_funcall(obj, rb_intern("other"), 0); + return rb_str_new2("blah, blah, blah"); +} + +VALUE +rb_m(int argc, VALUE *argv, VALUE obj) { + VALUE o1, o2; + rb_scan_args(argc, argv, "1", &o1, &o2); +} + BODY + + parser.handle_method 'method', 'rb_cObject', 'm', 'rb_m', -1 + + m = @top_level.find_module_named('Object').method_list.first + + assert_equal 'm', m.name + assert_equal @top_level, m.file + assert_equal 115, m.offset + assert_equal 7, m.line + + assert_equal '(p1)', m.params + end + + + def test_handle_method_args_0 + parser = util_parser "Document-method: BasicObject#==\n blah */" + + parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 0 + + bo = @top_level.find_module_named 'BasicObject' + + assert_equal 1, bo.method_list.length + + equals2 = bo.method_list.first + + assert_equal '()', equals2.params + end + + def test_handle_method_args_1 parser = util_parser "Document-method: BasicObject#==\n blah */" parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 1 @@ -753,7 +840,37 @@ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] equals2 = bo.method_list.first - assert_equal '==', equals2.name + assert_equal '(p1)', equals2.params + end + + def test_handle_method_args_2 + parser = util_parser "Document-method: BasicObject#==\n blah */" + + parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 2 + + bo = @top_level.find_module_named 'BasicObject' + + assert_equal 1, bo.method_list.length + + equals2 = bo.method_list.first + + assert_equal '(p1, p2)', equals2.params + end + + # test_handle_args_minus_1 handled by test_handle_method + + def test_handle_method_args_minus_2 + parser = util_parser "Document-method: BasicObject#==\n blah */" + + parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', -2 + + bo = @top_level.find_module_named 'BasicObject' + + assert_equal 1, bo.method_list.length + + equals2 = bo.method_list.first + + assert_equal '(*args)', equals2.params end def test_handle_method_initialize @@ -808,6 +925,7 @@ Init_IO(void) { read_method = klass.method_list.first assert_equal "read", read_method.name assert_equal "Method Comment! ", read_method.comment + assert_equal "rb_io_s_read", read_method.c_function assert read_method.singleton end @@ -898,6 +1016,65 @@ Init_IO(void) { assert read_method.singleton end + def test_rb_scan_args + parser = util_parser '' + + assert_equal '(p1)', + parser.rb_scan_args('rb_scan_args(a, b, "1",)') + assert_equal '(p1, p2)', + parser.rb_scan_args('rb_scan_args(a, b, "2",)') + + assert_equal '(p1 = v1)', + parser.rb_scan_args('rb_scan_args(a, b, "01",)') + assert_equal '(p1 = v1, p2 = v2)', + parser.rb_scan_args('rb_scan_args(a, b, "02",)') + + assert_equal '(p1, p2 = v2)', + parser.rb_scan_args('rb_scan_args(a, b, "11",)') + + assert_equal '(p1, *args)', + parser.rb_scan_args('rb_scan_args(a, b, "1*",)') + assert_equal '(p1, p2 = {})', + parser.rb_scan_args('rb_scan_args(a, b, "1:",)') + assert_equal '(p1, &block)', + parser.rb_scan_args('rb_scan_args(a, b, "1&",)') + + assert_equal '(p1, p2)', + parser.rb_scan_args('rb_scan_args(a, b, "101",)') + + assert_equal '(p1, p2 = v2, p3)', + parser.rb_scan_args('rb_scan_args(a, b, "111",)') + + assert_equal '(p1, *args, p3)', + parser.rb_scan_args('rb_scan_args(a, b, "1*1",)') + + assert_equal '(p1, p2 = v2, *args)', + parser.rb_scan_args('rb_scan_args(a, b, "11*",)') + assert_equal '(p1, p2 = v2, p3 = {})', + parser.rb_scan_args('rb_scan_args(a, b, "11:",)') + assert_equal '(p1, p2 = v2, &block)', + parser.rb_scan_args('rb_scan_args(a, b, "11&",)') + + assert_equal '(p1, p2 = v2, *args, p4, p5 = {}, &block)', + parser.rb_scan_args('rb_scan_args(a, b, "11*1:&",)') + + # The following aren't valid according to spec but are according to the + # implementation. + assert_equal '(*args)', + parser.rb_scan_args('rb_scan_args(a, b, "*",)') + assert_equal '(p1 = {})', + parser.rb_scan_args('rb_scan_args(a, b, ":",)') + assert_equal '(&block)', + parser.rb_scan_args('rb_scan_args(a, b, "&",)') + + assert_equal '(*args, p2 = {})', + parser.rb_scan_args('rb_scan_args(a, b, "*:",)') + assert_equal '(p1 = {}, &block)', + parser.rb_scan_args('rb_scan_args(a, b, ":&",)') + assert_equal '(*args, p2 = {}, &block)', + parser.rb_scan_args('rb_scan_args(a, b, "*:&",)') + end + def util_get_class(content, name) @parser = util_parser content @parser.scan diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index dcaf561369..ff1f1c9191 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -32,6 +32,36 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase @tempfile2.close end + def test_collect_first_comment + p = util_parser <<-CONTENT +# first + +# second +class C; end + CONTENT + + comment = p.collect_first_comment + + assert_equal "# first\n", comment + end + + def test_collect_first_comment_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + @options.encoding = Encoding::CP852 + + p = util_parser <<-CONTENT +# first + +# second +class C; end + CONTENT + + comment = p.collect_first_comment + + assert_equal Encoding::CP852, comment.encoding + end + def test_extract_call_seq m = RDoc::AnyMethod.new nil, 'm' p = util_parser '' @@ -156,6 +186,42 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal expected, comment end + def test_remove_private_comments_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + util_parser '' + + comment = <<-EOS +# This is text +#-- +# this is private + EOS + comment.force_encoding Encoding::IBM437 + + @parser.remove_private_comments comment + + assert_equal Encoding::IBM437, comment.encoding + end + + def test_remove_private_comments_long + util_parser '' + + comment = <<-EOS +#----- +#++ +# this is text +#----- + EOS + + expected = <<-EOS +# this is text + EOS + + @parser.remove_private_comments(comment) + + assert_equal expected, comment + end + def test_remove_private_comments_rule util_parser '' @@ -193,6 +259,45 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal expected, comment end + def test_remove_private_comments_toggle_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + util_parser '' + + comment = <<-EOS +# This is text +#-- +# this is private +#++ +# This is text again. + EOS + + comment.force_encoding Encoding::IBM437 + + @parser.remove_private_comments comment + + assert_equal Encoding::IBM437, comment.encoding + end + + def test_remove_private_comments_toggle_encoding_ruby_bug? + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + util_parser '' + + comment = <<-EOS +#-- +# this is private +#++ +# This is text again. + EOS + + comment.force_encoding Encoding::IBM437 + + @parser.remove_private_comments comment + + assert_equal Encoding::IBM437, comment.encoding + end + def test_look_for_directives_in_commented util_parser "" @@ -310,6 +415,8 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal klass, alas.parent assert_equal 'comment', alas.comment assert_equal @top_level, alas.file + assert_equal 0, alas.offset + assert_equal 1, alas.line end def test_parse_alias_singleton @@ -361,6 +468,8 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'foo', foo.name assert_equal 'my attr', foo.comment assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line end def test_parse_attr_accessor @@ -382,6 +491,8 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase assert_equal 'RW', foo.rw assert_equal 'my attr', foo.comment assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line bar = klass.attributes.last assert_equal 'bar', bar.name @@ -540,6 +651,9 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase foo = @top_level.classes.first assert_equal 'Foo', foo.full_name assert_equal 'my method', foo.comment + assert_equal [@top_level], foo.in_files + assert_equal 0, foo.offset + assert_equal 1, foo.line end def test_parse_class_ghost_method @@ -592,6 +706,57 @@ end assert_equal 2, foo.method_list.length end + def test_parse_multi_ghost_methods + util_parser <<-'CLASS' +class Foo + ## + # :method: one + # + # my method + + ## + # :method: two + # + # my method + + [:one, :two].each do |t| + eval("def #{t}; \"#{t}\"; end") + end +end + CLASS + + tk = @parser.get_tk + + @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + + assert_equal 2, foo.method_list.length + end + + def test_parse_const_fail_w_meta + util_parser <<-CLASS +class ConstFailMeta + ## + # :attr: one + # + # an attribute + + OtherModule.define_attr(self, :one) +end + CLASS + + tk = @parser.get_tk + + @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, '' + + const_fail_meta = @top_level.classes.first + assert_equal 'ConstFailMeta', const_fail_meta.full_name + + assert_equal 1, const_fail_meta.attributes.length + end + def test_parse_class_nested_superclass util_top_level foo = @top_level.add_module RDoc::NormalModule, 'Foo' @@ -654,6 +819,10 @@ end assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name } assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name } + b = RDoc::TopLevel.modules.first + assert_equal 10, b.offset + assert_equal 2, b.line + # make sure method/alias was not added to enclosing class/module a = RDoc::TopLevel.all_classes_hash['A'] assert_empty a.method_list @@ -792,6 +961,8 @@ EOF assert_equal 'RW', foo.rw assert_equal 'my attr', foo.comment assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line assert_equal nil, foo.viewer assert_equal true, foo.document_children @@ -821,6 +992,8 @@ EOF assert_equal 'foo', foo.name assert_equal 'my method', foo.comment assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line assert_equal [], foo.aliases assert_equal nil, foo.block_params @@ -848,6 +1021,25 @@ EOF assert_equal stream, foo.token_stream end + def test_parse_constant + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "A = v" + + tk = @parser.get_tk + + @parser.parse_constant klass, tk, '' + + foo = klass.constants.first + + assert_equal 'A', foo.name + assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line + end + def test_parse_constant_attrasgn util_top_level @@ -908,6 +1100,8 @@ EOF assert_equal 'foo', foo.name assert_equal 'my method', foo.comment assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line assert_equal [], foo.aliases assert_equal nil, foo.block_params @@ -942,6 +1136,27 @@ EOF assert_equal stream, foo.token_stream end + def test_parse_meta_method_block + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + + comment = "##\n# my method\n" + + content = <<-CONTENT +inline(:my_method) do |*args| + "this method causes z to disappear" +end + CONTENT + + util_parser content + + tk = @parser.get_tk + + @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_nil @parser.get_tk + end + def test_parse_meta_method_name klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -1046,6 +1261,8 @@ EOF assert_equal 'foo', foo.name assert_equal 'my method', foo.comment assert_equal @top_level, foo.file + assert_equal 0, foo.offset + assert_equal 1, foo.line assert_equal [], foo.aliases assert_equal nil, foo.block_params @@ -1327,6 +1544,28 @@ end assert_equal 'my method', bar.comment end + def test_parse_statements_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + @options.encoding = Encoding::CP852 + + content = <<-EOF +class Foo + ## + # this is my method + add_my_method :foo +end + EOF + + util_parser content + + @parser.parse_statements @top_level + + foo = @top_level.classes.first.method_list.first + assert_equal 'foo', foo.name + assert_equal 'this is my method', foo.comment + assert_equal Encoding::CP852, foo.comment.encoding + end + def test_parse_statements_identifier_meta_method content = <<-EOF class Foo @@ -1338,7 +1577,7 @@ end util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first.method_list.first assert_equal 'foo', foo.name @@ -1354,7 +1593,7 @@ end util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first.method_list[0] assert_equal 'foo', foo.name @@ -1387,7 +1626,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first.method_list[0] assert_equal 'foo', foo.name @@ -1453,7 +1692,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level constants = @top_level.classes.first.constants @@ -1500,7 +1739,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first.attributes.first assert_equal 'foo', foo.name @@ -1512,7 +1751,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first.attributes.first assert_equal 'foo', foo.name @@ -1524,7 +1763,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first assert_equal 'Foo', foo.name @@ -1536,7 +1775,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo, s_foo = @top_level.modules.first.method_list assert_equal 'foo', foo.name, 'instance method name' @@ -1553,7 +1792,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.classes.first.method_list.first assert_equal 'foo', foo.name @@ -1565,7 +1804,7 @@ EOF util_parser content - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level assert_equal 1, @top_level.requires.length end @@ -1583,7 +1822,7 @@ class A end RUBY - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level c_a = @top_level.classes.first assert_equal 'A', c_a.full_name @@ -1691,8 +1930,77 @@ end while @parser.get_tk do end end - def test_stopdoc_after_comment + def test_scan_cr + content = <<-CONTENT +class C\r + def m\r + a=\\\r + 123\r + end\r +end\r + CONTENT + + util_parser content + @parser.scan + + c = @top_level.classes.first + + assert_equal 1, c.method_list.length + end + + def test_scan_block_comment + content = <<-CONTENT +=begin rdoc +Foo comment +=end + +class Foo + +=begin +m comment +=end + + def m() end +end + CONTENT + + util_parser content + + @parser.scan + + foo = @top_level.classes.first + + assert_equal 'Foo comment', foo.comment + + m = foo.method_list.first + + assert_equal 'm comment', m.comment + end + + def test_scan_meta_method_block + content = <<-CONTENT +class C + + ## + # my method + + inline(:my_method) do |*args| + "this method used to cause z to disappear" + end + + def z + end + CONTENT + + util_parser content + + @parser.scan + + assert_equal 2, @top_level.classes.first.method_list.length + end + + def test_stopdoc_after_comment util_parser <<-EOS module Bar # hello @@ -1706,7 +2014,7 @@ end end EOS - @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, '' + @parser.parse_statements @top_level foo = @top_level.modules.first.modules.first assert_equal 'Foo', foo.name diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index d65e2f3427..0f465d724f 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -9,6 +9,8 @@ require 'tmpdir' class TestRDocRDoc < MiniTest::Unit::TestCase def setup + RDoc::TopLevel.reset + @rdoc = RDoc::RDoc.new @rdoc.options = RDoc::Options.new @@ -45,7 +47,7 @@ class TestRDocRDoc < MiniTest::Unit::TestCase assert_empty files end - def test_remove_unparsable + def test_remove_unparseable file_list = %w[ blah.class blah.eps @@ -62,13 +64,14 @@ class TestRDocRDoc < MiniTest::Unit::TestCase skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir Dir.mktmpdir {|d| - path = File.join(d, 'testdir') + path = File.join d, 'testdir' last = @rdoc.setup_output_dir path, false assert_empty last assert File.directory? path + assert File.exist? @rdoc.output_flag_file path } end @@ -149,6 +152,17 @@ class TestRDocRDoc < MiniTest::Unit::TestCase end end + def test_update_output_dir_dont + skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir + + Dir.mktmpdir do |d| + @rdoc.options.update_output_dir = false + @rdoc.update_output_dir d, Time.now, {} + + refute File.exist? "#{d}/created.rid" + end + end + def test_update_output_dir_dry_run skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index 75ecfefe8e..2d735044dd 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -390,6 +390,16 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase assert_match %r%^=== Implementation from Foo%, out end + def test_display_method_overriden + util_multi_store + + out, = capture_io do + @driver.display_method 'Bar#override' + end + + refute_match %r%must not be displayed%, out + end + def test_display_name_not_found_class util_store @@ -495,6 +505,32 @@ Foo::Bar#bother assert_equal expected, items end + def test_filter_methods + util_multi_store + + name = 'Bar#override' + + found = @driver.load_methods_matching name + + sorted = @driver.filter_methods found, name + + expected = [[@store2, [@override]]] + + assert_equal expected, sorted + end + + def test_filter_methods_not_found + util_multi_store + + name = 'Bar#inherit' + + found = @driver.load_methods_matching name + + sorted = @driver.filter_methods found, name + + assert_equal found, sorted + end + def test_formatter tty = Object.new def tty.tty?() true; end @@ -533,6 +569,16 @@ Foo::Bar#bother assert_equal :class, @driver.method_type('::') end + def test_name_regexp + assert_equal %r%^RDoc::AnyMethod#new$%, + @driver.name_regexp('RDoc::AnyMethod#new') + assert_equal %r%^RDoc::AnyMethod::new$%, + @driver.name_regexp('RDoc::AnyMethod::new') + + assert_equal %r%^RDoc::AnyMethod(#|::)new$%, + @driver.name_regexp('RDoc::AnyMethod.new') + end + def test_list_known_classes util_store @@ -766,6 +812,7 @@ Foo::Bar#bother @mAmbiguous = RDoc::NormalModule.new 'Ambiguous' @cFoo = RDoc::NormalClass.new 'Foo' + @cBar = RDoc::NormalClass.new 'Bar' @cBar.superclass = 'Foo' @cFoo_Baz = RDoc::NormalClass.new 'Baz' @@ -774,10 +821,15 @@ Foo::Bar#bother @baz = RDoc::AnyMethod.new nil, 'baz' @cBar.add_method @baz + @override = RDoc::AnyMethod.new nil, 'override' + @override.comment = 'must be displayed' + @cBar.add_method @override + @store2.save_class @mAmbiguous @store2.save_class @cBar @store2.save_class @cFoo_Baz + @store2.save_method @cBar, @override @store2.save_method @cBar, @baz @store2.save_cache @@ -824,6 +876,11 @@ Foo::Bar#bother @inherit = RDoc::AnyMethod.new nil, 'inherit' @cFoo.add_method @inherit + # overriden by Bar in multi_store + @overriden = RDoc::AnyMethod.new nil, 'override' + @overriden.comment = 'must not be displayed' + @cFoo.add_method @overriden + @store.save_class @cFoo @store.save_class @cFoo_Bar @store.save_class @cFoo_Baz @@ -836,6 +893,7 @@ Foo::Bar#bother @store.save_method @cFoo_Bar, @attr @store.save_method @cFoo, @inherit + @store.save_method @cFoo, @overriden @store.save_cache diff --git a/test/rdoc/test_rdoc_stats.rb b/test/rdoc/test_rdoc_stats.rb index 0032c75669..17458adaa4 100644 --- a/test/rdoc/test_rdoc_stats.rb +++ b/test/rdoc/test_rdoc_stats.rb @@ -13,8 +13,78 @@ class TestRDocStats < MiniTest::Unit::TestCase @s = RDoc::Stats.new 0 end + def test_report_attr + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + a = RDoc::Attr.new nil, 'a', 'RW', nil + a.record_location tl + c.add_attribute a + + RDoc::TopLevel.complete :public + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +class C # is documented + + attr_accessor :a # in file file.rb +end + EXPECTED + + assert_equal expected, report + end + + def test_report_attr_documented + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + a = RDoc::Attr.new nil, 'a', 'RW', 'a' + a.record_location tl + c.add_attribute a + + RDoc::TopLevel.complete :public + + report = @s.report + + assert_equal @s.great_job, report + end + + def test_report_constant + tl = RDoc::TopLevel.new 'file.rb' + m = tl.add_module RDoc::NormalModule, 'M' + m.record_location tl + m.comment = 'M' + + c = RDoc::Constant.new 'C', nil, nil + c.record_location tl + m.add_constant c + + RDoc::TopLevel.complete :public + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +module M # is documented + + # in file file.rb + C = nil +end + EXPECTED + + assert_equal expected, report + end + def test_report_constant_alias - tl = RDoc::TopLevel.new 'fake.rb' + tl = RDoc::TopLevel.new 'file.rb' mod = tl.add_module RDoc::NormalModule, 'M' c = tl.add_class RDoc::NormalClass, 'C' @@ -34,5 +104,440 @@ class TestRDocStats < MiniTest::Unit::TestCase assert_match(/class Object/, report) end + def test_report_constant_documented + tl = RDoc::TopLevel.new 'file.rb' + m = tl.add_module RDoc::NormalModule, 'M' + m.record_location tl + m.comment = 'M' + + c = RDoc::Constant.new 'C', nil, 'C' + c.record_location tl + m.add_constant c + + RDoc::TopLevel.complete :public + + report = @s.report + + assert_equal @s.great_job, report + end + + def test_report_class + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + c.add_method m + m.comment = 'm' + + RDoc::TopLevel.complete :public + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +# in files: +# file.rb + +class C +end + EXPECTED + + assert_equal expected, report + end + + def test_report_class_documented + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + c.add_method m + m.comment = 'm' + + RDoc::TopLevel.complete :public + + report = @s.report + + assert_equal @s.great_job, report + end + + def test_report_class_documented_level_1 + tl = RDoc::TopLevel.new 'file.rb' + c1 = tl.add_class RDoc::NormalClass, 'C1' + c1.record_location tl + c1.comment = 'C1' + + m1 = RDoc::AnyMethod.new nil, 'm1' + m1.record_location tl + c1.add_method m1 + m1.comment = 'm1' + + c2 = tl.add_class RDoc::NormalClass, 'C2' + c2.record_location tl + + m2 = RDoc::AnyMethod.new nil, 'm2' + m2.record_location tl + c2.add_method m2 + m2.comment = 'm2' + + RDoc::TopLevel.complete :public + + @s.coverage_level = 1 + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + + +# in files: +# file.rb + +class C2 +end + EXPECTED + + assert_equal expected, report + end + + def test_report_class_empty + tl = RDoc::TopLevel.new 'file.rb' + tl.add_class RDoc::NormalClass, 'C' + + RDoc::TopLevel.complete :public + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +# class C is referenced but empty. +# +# It probably came from another project. I'm sorry I'm holding it against you. + EXPECTED + + assert_equal expected, report + end + + def test_report_class_empty_2 + tl = RDoc::TopLevel.new 'file.rb' + c1 = tl.add_class RDoc::NormalClass, 'C1' + c1.record_location tl + + c2 = tl.add_class RDoc::NormalClass, 'C2' + c2.record_location tl + c2.comment = 'C2' + + RDoc::TopLevel.complete :public + + @s.coverage_level = 1 + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +# in files: +# file.rb + +class C1 +end + + EXPECTED + + assert_equal expected, report + end + + def test_report_class_method_documented + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + c.add_method m + m.comment = 'm' + + RDoc::TopLevel.complete :public + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +# in files: +# file.rb + +class C +end + EXPECTED + + assert_equal expected, report + end + + def test_report_empty + RDoc::TopLevel.complete :public + + report = @s.report + + assert_equal @s.great_job, report + end + + def test_report_method + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m1 = RDoc::AnyMethod.new nil, 'm1' + m1.record_location tl + c.add_method m1 + + m2 = RDoc::AnyMethod.new nil, 'm2' + m2.record_location tl + c.add_method m2 + m2.comment = 'm2' + + RDoc::TopLevel.complete :public + + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +class C # is documented + + # in file file.rb + def m1; end + +end + EXPECTED + + assert_equal expected, report + end + + def test_report_method_documented + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + c.add_method m + m.comment = 'm' + + RDoc::TopLevel.complete :public + + report = @s.report + + assert_equal @s.great_job, report + end + + def test_report_method_parameters + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m1 = RDoc::AnyMethod.new nil, 'm1' + m1.record_location tl + m1.params = '(p1, p2)' + m1.comment = 'Stuff with +p1+' + c.add_method m1 + + m2 = RDoc::AnyMethod.new nil, 'm2' + m2.record_location tl + c.add_method m2 + m2.comment = 'm2' + + RDoc::TopLevel.complete :public + + @s.coverage_level = 1 + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +class C # is documented + + # in file file.rb + # +p2+ is not documented + def m1(p1, p2); end + +end + EXPECTED + + assert_equal expected, report + end + + def test_report_method_parameters_documented + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + m.params = '(p1)' + m.comment = 'Stuff with +p1+' + c.add_method m + + RDoc::TopLevel.complete :public + + @s.coverage_level = 1 + report = @s.report + + assert_equal @s.great_job, report + end + + def test_report_method_parameters_yield + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + m.call_seq = <<-SEQ +m(a) { |c| ... } +m(a, b) { |c, d| ... } + SEQ + m.comment = 'Stuff with +a+, yields +c+ for you to do stuff with' + c.add_method m + + RDoc::TopLevel.complete :public + + @s.coverage_level = 1 + report = @s.report + + expected = <<-EXPECTED +The following items are not documented: + +class C # is documented + + # in file file.rb + # +b+, +d+ is not documented + def m; end + +end + EXPECTED + + assert_equal expected, report + end + + def test_summary + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + + m = tl.add_module RDoc::NormalModule, 'M' + m.record_location tl + + a = RDoc::Attr.new nil, 'a', 'RW', nil + a.record_location tl + c.add_attribute a + + c_c = RDoc::Constant.new 'C', nil, nil + c_c.record_location tl + c.add_constant c_c + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + c.add_method m + + RDoc::TopLevel.complete :public + + summary = @s.summary + summary.sub!(/Elapsed:.*/, '') + + expected = <<-EXPECTED +Files: 0 + +Classes: 1 (1 undocumented) +Modules: 1 (1 undocumented) +Constants: 1 (1 undocumented) +Attributes: 1 (1 undocumented) +Methods: 1 (1 undocumented) + +Total: 5 (5 undocumented) + 0.00% documented + + EXPECTED + + assert_equal summary, expected + end + + def test_summary_level_false + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + + RDoc::TopLevel.complete :public + + @s.coverage_level = false + + summary = @s.summary + summary.sub!(/Elapsed:.*/, '') + + expected = <<-EXPECTED +Files: 0 + +Classes: 1 (1 undocumented) +Modules: 0 (0 undocumented) +Constants: 0 (0 undocumented) +Attributes: 0 (0 undocumented) +Methods: 0 (0 undocumented) + +Total: 1 (1 undocumented) + 0.00% documented + + EXPECTED + + assert_equal summary, expected + end + + def test_summary_level_1 + tl = RDoc::TopLevel.new 'file.rb' + c = tl.add_class RDoc::NormalClass, 'C' + c.record_location tl + c.comment = 'C' + + m = RDoc::AnyMethod.new nil, 'm' + m.record_location tl + m.params = '(p1, p2)' + m.comment = 'Stuff with +p1+' + c.add_method m + + RDoc::TopLevel.complete :public + + @s.coverage_level = 1 + @s.report + + summary = @s.summary + summary.sub!(/Elapsed:.*/, '') + + expected = <<-EXPECTED +Files: 0 + +Classes: 1 (0 undocumented) +Modules: 0 (0 undocumented) +Constants: 0 (0 undocumented) +Attributes: 0 (0 undocumented) +Methods: 1 (0 undocumented) +Parameters: 2 (1 undocumented) + +Total: 4 (1 undocumented) + 75.00% documented + + EXPECTED + + assert_equal summary, expected + end + end diff --git a/test/rdoc/test_rdoc_task.rb b/test/rdoc/test_rdoc_task.rb index 2b72e7f654..c17a5c8b38 100644 --- a/test/rdoc/test_rdoc_task.rb +++ b/test/rdoc/test_rdoc_task.rb @@ -6,25 +6,29 @@ class TestRDocTask < MiniTest::Unit::TestCase def setup Rake::Task.clear + + @t = RDoc::Task.new end - def test_inline_source - t = RDoc::Task.new + def test_clobber_task_description + assert_equal 'Remove RDoc HTML files', @t.clobber_task_description + end + def test_inline_source _, err = capture_io do - assert t.inline_source + assert @t.inline_source end assert_equal "RDoc::Task#inline_source is deprecated\n", err _, err = capture_io do - t.inline_source = false + @t.inline_source = false end assert_equal "RDoc::Task#inline_source is deprecated\n", err capture_io do - assert t.inline_source + assert @t.inline_source end end @@ -51,6 +55,14 @@ class TestRDocTask < MiniTest::Unit::TestCase assert_equal %w[-o html -f ri], rdoc_task.option_list end + def test_rdoc_task_description + assert_equal 'Build RDoc HTML files', @t.rdoc_task_description + end + + def test_rerdoc_task_description + assert_equal 'Rebuild RDoc HTML files', @t.rerdoc_task_description + end + def test_tasks_creation_with_custom_name_string rd = RDoc::Task.new("rdoc_dev") assert Rake::Task[:rdoc_dev] @@ -60,7 +72,14 @@ class TestRDocTask < MiniTest::Unit::TestCase end def test_tasks_creation_with_custom_name_hash - options = { :rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force" } + options = { + :rdoc => "rdoc", + :clobber_rdoc => "rdoc:clean", + :rerdoc => "rdoc:force" + } + + Rake::Task.clear + rd = RDoc::Task.new(options) assert Rake::Task[:"rdoc"] assert Rake::Task[:"rdoc:clean"] diff --git a/test/rdoc/test_rdoc_text.rb b/test/rdoc/test_rdoc_text.rb index 600de30b0b..ebc92dc1a5 100644 --- a/test/rdoc/test_rdoc_text.rb +++ b/test/rdoc/test_rdoc_text.rb @@ -134,6 +134,31 @@ The comments associated with assert_equal expected, strip_hashes(text) end + def test_strip_hashes_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + text = <<-TEXT +## +# we don't worry too much. +# +# The comments associated with + TEXT + + text.force_encoding Encoding::CP852 + + expected = <<-EXPECTED + + we don't worry too much. + + The comments associated with + EXPECTED + + stripped = strip_hashes text + + assert_equal expected, stripped + assert_equal Encoding::CP852, stripped.encoding + end + def test_strip_newlines assert_equal ' ', strip_newlines("\n \n") @@ -144,6 +169,21 @@ The comments associated with assert_equal 'hi', strip_newlines("\n\nhi\n\n") end + def test_strip_newlines_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + assert_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check' + + text = " \n" + text.force_encoding Encoding::US_ASCII + + stripped = strip_newlines text + + assert_equal ' ', stripped + + assert_equal Encoding::US_ASCII, stripped.encoding + end + def test_strip_stars text = <<-TEXT /* @@ -163,6 +203,30 @@ The comments associated with assert_equal expected, strip_stars(text) end + def test_strip_stars_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + text = <<-TEXT +/* + * * we don't worry too much. + * + * The comments associated with + */ + TEXT + + text.force_encoding Encoding::CP852 + + expected = <<-EXPECTED + + * we don't worry too much. + + The comments associated with + EXPECTED + + assert_equal expected, strip_stars(text) + assert_equal Encoding::CP852, text.encoding + end + def test_to_html_apostrophe assert_equal '‘a', to_html("'a") assert_equal 'a’', to_html("a'") diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index f40a42b3f6..a1eef0fa22 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -28,7 +28,7 @@ class TestRDocTopLevel < XrefTestCase end def test_class_complete - @c2.add_module_alias @c2_c3, 'A1' + @c2.add_module_alias @c2_c3, 'A1', @top_level RDoc::TopLevel.complete :public |