aboutsummaryrefslogtreecommitdiffstats
path: root/test/rdoc/test_rdoc_stats.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rdoc/test_rdoc_stats.rb')
-rw-r--r--test/rdoc/test_rdoc_stats.rb352
1 files changed, 228 insertions, 124 deletions
diff --git a/test/rdoc/test_rdoc_stats.rb b/test/rdoc/test_rdoc_stats.rb
index 0bf08334da..5073e53b7e 100644
--- a/test/rdoc/test_rdoc_stats.rb
+++ b/test/rdoc/test_rdoc_stats.rb
@@ -1,29 +1,46 @@
-require 'rubygems'
-require 'minitest/autorun'
-require 'rdoc/stats'
-require 'rdoc/code_objects'
-require 'rdoc/markup'
-require 'rdoc/parser'
+require 'rdoc/test_case'
-class TestRDocStats < MiniTest::Unit::TestCase
+class TestRDocStats < RDoc::TestCase
def setup
- RDoc::TopLevel.reset
+ super
- @s = RDoc::Stats.new 0
+ @s = RDoc::Stats.new @store, 0
+
+ @tl = @store.add_file 'file.rb'
+ @tl.parser = RDoc::Parser::Ruby
+ end
+
+ def test_doc_stats
+ c = RDoc::CodeObject.new
+
+ assert_equal [1, 1], @s.doc_stats([c])
+ end
+
+ def test_doc_stats_documented
+ c = RDoc::CodeObject.new
+ c.comment = comment 'x'
+
+ assert_equal [1, 0], @s.doc_stats([c])
+ end
+
+ def test_doc_stats_display_eh
+ c = RDoc::CodeObject.new
+ c.ignore
+
+ assert_equal [0, 0], @s.doc_stats([c])
end
def test_report_attr
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
- c.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
a = RDoc::Attr.new nil, 'a', 'RW', nil
- a.record_location tl
+ a.record_location @tl
c.add_attribute a
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -40,33 +57,46 @@ end
end
def test_report_attr_documented
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
- c.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
a = RDoc::Attr.new nil, 'a', 'RW', 'a'
- a.record_location tl
+ a.record_location @tl
c.add_attribute a
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
assert_equal @s.great_job, report
end
+ def test_report_attr_line
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
+
+ a = RDoc::Attr.new nil, 'a', 'RW', nil
+ a.record_location @tl
+ a.line = 3
+ c.add_attribute a
+
+ @store.complete :public
+
+ assert_match '# in file file.rb:3', @s.report
+ end
+
def test_report_constant
- tl = RDoc::TopLevel.new 'file.rb'
- m = tl.add_module RDoc::NormalModule, 'M'
- m.record_location tl
- m.add_comment 'M', tl
+ m = @tl.add_module RDoc::NormalModule, 'M'
+ m.record_location @tl
+ m.add_comment 'M', @tl
c = RDoc::Constant.new 'C', nil, nil
- c.record_location tl
+ c.record_location @tl
m.add_constant c
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -84,18 +114,17 @@ end
end
def test_report_constant_alias
- tl = RDoc::TopLevel.new 'file.rb'
- mod = tl.add_module RDoc::NormalModule, 'M'
+ mod = @tl.add_module RDoc::NormalModule, 'M'
- c = tl.add_class RDoc::NormalClass, 'C'
+ c = @tl.add_class RDoc::NormalClass, 'C'
mod.add_constant c
ca = RDoc::Constant.new 'CA', nil, nil
ca.is_alias_for = c
- tl.add_constant ca
+ @tl.add_constant ca
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -105,33 +134,46 @@ end
end
def test_report_constant_documented
- tl = RDoc::TopLevel.new 'file.rb'
- m = tl.add_module RDoc::NormalModule, 'M'
- m.record_location tl
+ 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
+ c.record_location @tl
m.add_constant c
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
assert_equal @s.great_job, report
end
+ def test_report_constant_line
+ m = @tl.add_module RDoc::NormalModule, 'M'
+ m.record_location @tl
+ m.add_comment 'M', @tl
+
+ c = RDoc::Constant.new 'C', nil, nil
+ c.record_location @tl
+ c.line = 5
+ m.add_constant c
+
+ @store.complete :public
+
+ assert_match '# in file file.rb:5', @s.report
+ end
+
def test_report_class
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
c.add_method m
m.comment = 'm'
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -148,18 +190,31 @@ end
assert_equal expected, report
end
+ def test_report_skip_object
+ c = @tl.add_class RDoc::NormalClass, 'Object'
+ c.record_location @tl
+
+ m = RDoc::AnyMethod.new nil, 'm'
+ m.record_location @tl
+ c.add_method m
+ m.comment = 'm'
+
+ @store.complete :public
+
+ refute_match %r%^class Object$%, @s.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.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
c.add_method m
m.comment = 'm'
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -167,25 +222,24 @@ end
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.add_comment 'C1', tl
+ c1 = @tl.add_class RDoc::NormalClass, 'C1'
+ c1.record_location @tl
+ c1.add_comment 'C1', @tl
m1 = RDoc::AnyMethod.new nil, 'm1'
- m1.record_location tl
+ m1.record_location @tl
c1.add_method m1
m1.comment = 'm1'
- c2 = tl.add_class RDoc::NormalClass, 'C2'
- c2.record_location tl
+ c2 = @tl.add_class RDoc::NormalClass, 'C2'
+ c2.record_location @tl
m2 = RDoc::AnyMethod.new nil, 'm2'
- m2.record_location tl
+ m2.record_location @tl
c2.add_method m2
m2.comment = 'm2'
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = 1
@@ -206,10 +260,9 @@ end
end
def test_report_class_empty
- tl = RDoc::TopLevel.new 'file.rb'
- tl.add_class RDoc::NormalClass, 'C'
+ @tl.add_class RDoc::NormalClass, 'C'
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -225,15 +278,14 @@ The following items are not documented:
end
def test_report_class_empty_2
- tl = RDoc::TopLevel.new 'file.rb'
- c1 = tl.add_class RDoc::NormalClass, 'C1'
- c1.record_location tl
+ c1 = @tl.add_class RDoc::NormalClass, 'C1'
+ c1.record_location @tl
- c2 = tl.add_class RDoc::NormalClass, 'C2'
- c2.record_location tl
- c2.add_comment 'C2', tl
+ c2 = @tl.add_class RDoc::NormalClass, 'C2'
+ c2.record_location @tl
+ c2.add_comment 'C2', @tl
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = 1
report = @s.report
@@ -253,16 +305,15 @@ end
end
def test_report_class_method_documented
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
c.add_method m
m.comment = 'm'
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -279,8 +330,19 @@ end
assert_equal expected, report
end
+ def test_report_class_module_ignore
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.ignore
+
+ @store.complete :public
+
+ report = @s.report_class_module c
+
+ assert_nil report
+ end
+
def test_report_empty
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -288,21 +350,20 @@ end
end
def test_report_method
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
- c.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m1 = RDoc::AnyMethod.new nil, 'm1'
- m1.record_location tl
+ m1.record_location @tl
c.add_method m1
m2 = RDoc::AnyMethod.new nil, 'm2'
- m2.record_location tl
+ m2.record_location @tl
c.add_method m2
m2.comment = 'm2'
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
@@ -320,42 +381,89 @@ end
assert_equal expected, report
end
+ def test_report_method_class
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
+
+ m1 = RDoc::AnyMethod.new nil, 'm1'
+ m1.record_location @tl
+ m1.singleton = true
+ c.add_method m1
+
+ m2 = RDoc::AnyMethod.new nil, 'm2'
+ m2.record_location @tl
+ m2.singleton = true
+ c.add_method m2
+ m2.comment = 'm2'
+
+ @store.complete :public
+
+ report = @s.report
+
+ expected = <<-EXPECTED
+The following items are not documented:
+
+class C # is documented
+
+ # in file file.rb
+ def self.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.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
c.add_method m
m.comment = 'm'
- RDoc::TopLevel.complete :public
+ @store.complete :public
report = @s.report
assert_equal @s.great_job, report
end
+ def test_report_method_line
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
+
+ m1 = RDoc::AnyMethod.new nil, 'm1'
+ m1.record_location @tl
+ m1.line = 4
+ c.add_method m1
+
+ @store.complete :public
+
+ assert_match '# in file file.rb:4', @s.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.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m1 = RDoc::AnyMethod.new nil, 'm1'
- m1.record_location tl
+ 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
+ m2.record_location @tl
c.add_method m2
m2.comment = 'm2'
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = 1
report = @s.report
@@ -376,18 +484,18 @@ end
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.add_comment 'C', tl
+ @tl.parser = RDoc::Parser::Ruby
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
m.params = '(p1)'
m.comment = 'Stuff with +p1+'
c.add_method m
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = 1
report = @s.report
@@ -396,13 +504,12 @@ end
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.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
m.call_seq = <<-SEQ
m(a) { |c| ... }
m(a, b) { |c, d| ... }
@@ -410,7 +517,7 @@ m(a, b) { |c, d| ... }
m.comment = 'Stuff with +a+, yields +c+ for you to do stuff with'
c.add_method m
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = 1
report = @s.report
@@ -431,26 +538,25 @@ end
end
def test_summary
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
- m = tl.add_module RDoc::NormalModule, 'M'
- m.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
+ a.record_location @tl
c.add_attribute a
c_c = RDoc::Constant.new 'C', nil, nil
- c_c.record_location tl
+ c_c.record_location @tl
c.add_constant c_c
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
c.add_method m
- RDoc::TopLevel.complete :public
+ @store.complete :public
summary = @s.summary
summary.sub!(/Elapsed:.*/, '')
@@ -473,11 +579,10 @@ Total: 5 (5 undocumented)
end
def test_summary_level_false
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = false
@@ -502,18 +607,17 @@ Total: 1 (1 undocumented)
end
def test_summary_level_1
- tl = RDoc::TopLevel.new 'file.rb'
- c = tl.add_class RDoc::NormalClass, 'C'
- c.record_location tl
- c.add_comment 'C', tl
+ c = @tl.add_class RDoc::NormalClass, 'C'
+ c.record_location @tl
+ c.add_comment 'C', @tl
m = RDoc::AnyMethod.new nil, 'm'
- m.record_location tl
+ m.record_location @tl
m.params = '(p1, p2)'
m.comment = 'Stuff with +p1+'
c.add_method m
- RDoc::TopLevel.complete :public
+ @store.complete :public
@s.coverage_level = 1
@s.report