1require 'rdoc/test_case' 2 3class TestRDocStats < RDoc::TestCase 4 5 def setup 6 super 7 8 @s = RDoc::Stats.new @store, 0 9 10 @tl = @store.add_file 'file.rb' 11 @tl.parser = RDoc::Parser::Ruby 12 end 13 14 def test_doc_stats 15 c = RDoc::CodeObject.new 16 17 assert_equal [1, 1], @s.doc_stats([c]) 18 end 19 20 def test_doc_stats_documented 21 c = RDoc::CodeObject.new 22 c.comment = comment 'x' 23 24 assert_equal [1, 0], @s.doc_stats([c]) 25 end 26 27 def test_doc_stats_display_eh 28 c = RDoc::CodeObject.new 29 c.ignore 30 31 assert_equal [0, 0], @s.doc_stats([c]) 32 end 33 34 def test_report_attr 35 c = @tl.add_class RDoc::NormalClass, 'C' 36 c.record_location @tl 37 c.add_comment 'C', @tl 38 39 a = RDoc::Attr.new nil, 'a', 'RW', nil 40 a.record_location @tl 41 c.add_attribute a 42 43 @store.complete :public 44 45 report = @s.report 46 47 expected = <<-EXPECTED 48The following items are not documented: 49 50class C # is documented 51 52 attr_accessor :a # in file file.rb 53end 54 EXPECTED 55 56 assert_equal expected, report 57 end 58 59 def test_report_attr_documented 60 c = @tl.add_class RDoc::NormalClass, 'C' 61 c.record_location @tl 62 c.add_comment 'C', @tl 63 64 a = RDoc::Attr.new nil, 'a', 'RW', 'a' 65 a.record_location @tl 66 c.add_attribute a 67 68 @store.complete :public 69 70 report = @s.report 71 72 assert_equal @s.great_job, report 73 end 74 75 def test_report_attr_line 76 c = @tl.add_class RDoc::NormalClass, 'C' 77 c.record_location @tl 78 c.add_comment 'C', @tl 79 80 a = RDoc::Attr.new nil, 'a', 'RW', nil 81 a.record_location @tl 82 a.line = 3 83 c.add_attribute a 84 85 @store.complete :public 86 87 assert_match '# in file file.rb:3', @s.report 88 end 89 90 def test_report_constant 91 m = @tl.add_module RDoc::NormalModule, 'M' 92 m.record_location @tl 93 m.add_comment 'M', @tl 94 95 c = RDoc::Constant.new 'C', nil, nil 96 c.record_location @tl 97 m.add_constant c 98 99 @store.complete :public 100 101 report = @s.report 102 103 expected = <<-EXPECTED 104The following items are not documented: 105 106module M # is documented 107 108 # in file file.rb 109 C = nil 110end 111 EXPECTED 112 113 assert_equal expected, report 114 end 115 116 def test_report_constant_alias 117 mod = @tl.add_module RDoc::NormalModule, 'M' 118 119 c = @tl.add_class RDoc::NormalClass, 'C' 120 mod.add_constant c 121 122 ca = RDoc::Constant.new 'CA', nil, nil 123 ca.is_alias_for = c 124 125 @tl.add_constant ca 126 127 @store.complete :public 128 129 report = @s.report 130 131 # TODO change this to refute match, aliases should be ignored as they are 132 # programmer convenience constructs 133 assert_match(/class Object/, report) 134 end 135 136 def test_report_constant_documented 137 m = @tl.add_module RDoc::NormalModule, 'M' 138 m.record_location @tl 139 m.comment = 'M' 140 141 c = RDoc::Constant.new 'C', nil, 'C' 142 c.record_location @tl 143 m.add_constant c 144 145 @store.complete :public 146 147 report = @s.report 148 149 assert_equal @s.great_job, report 150 end 151 152 def test_report_constant_line 153 m = @tl.add_module RDoc::NormalModule, 'M' 154 m.record_location @tl 155 m.add_comment 'M', @tl 156 157 c = RDoc::Constant.new 'C', nil, nil 158 c.record_location @tl 159 c.line = 5 160 m.add_constant c 161 162 @store.complete :public 163 164 assert_match '# in file file.rb:5', @s.report 165 end 166 167 def test_report_class 168 c = @tl.add_class RDoc::NormalClass, 'C' 169 c.record_location @tl 170 171 m = RDoc::AnyMethod.new nil, 'm' 172 m.record_location @tl 173 c.add_method m 174 m.comment = 'm' 175 176 @store.complete :public 177 178 report = @s.report 179 180 expected = <<-EXPECTED 181The following items are not documented: 182 183# in files: 184# file.rb 185 186class C 187end 188 EXPECTED 189 190 assert_equal expected, report 191 end 192 193 def test_report_skip_object 194 c = @tl.add_class RDoc::NormalClass, 'Object' 195 c.record_location @tl 196 197 m = RDoc::AnyMethod.new nil, 'm' 198 m.record_location @tl 199 c.add_method m 200 m.comment = 'm' 201 202 @store.complete :public 203 204 refute_match %r%^class Object$%, @s.report 205 end 206 207 def test_report_class_documented 208 c = @tl.add_class RDoc::NormalClass, 'C' 209 c.record_location @tl 210 c.add_comment 'C', @tl 211 212 m = RDoc::AnyMethod.new nil, 'm' 213 m.record_location @tl 214 c.add_method m 215 m.comment = 'm' 216 217 @store.complete :public 218 219 report = @s.report 220 221 assert_equal @s.great_job, report 222 end 223 224 def test_report_class_documented_level_1 225 c1 = @tl.add_class RDoc::NormalClass, 'C1' 226 c1.record_location @tl 227 c1.add_comment 'C1', @tl 228 229 m1 = RDoc::AnyMethod.new nil, 'm1' 230 m1.record_location @tl 231 c1.add_method m1 232 m1.comment = 'm1' 233 234 c2 = @tl.add_class RDoc::NormalClass, 'C2' 235 c2.record_location @tl 236 237 m2 = RDoc::AnyMethod.new nil, 'm2' 238 m2.record_location @tl 239 c2.add_method m2 240 m2.comment = 'm2' 241 242 @store.complete :public 243 244 @s.coverage_level = 1 245 246 report = @s.report 247 248 expected = <<-EXPECTED 249The following items are not documented: 250 251 252# in files: 253# file.rb 254 255class C2 256end 257 EXPECTED 258 259 assert_equal expected, report 260 end 261 262 def test_report_class_empty 263 @tl.add_class RDoc::NormalClass, 'C' 264 265 @store.complete :public 266 267 report = @s.report 268 269 expected = <<-EXPECTED 270The following items are not documented: 271 272# class C is referenced but empty. 273# 274# It probably came from another project. I'm sorry I'm holding it against you. 275 EXPECTED 276 277 assert_equal expected, report 278 end 279 280 def test_report_class_empty_2 281 c1 = @tl.add_class RDoc::NormalClass, 'C1' 282 c1.record_location @tl 283 284 c2 = @tl.add_class RDoc::NormalClass, 'C2' 285 c2.record_location @tl 286 c2.add_comment 'C2', @tl 287 288 @store.complete :public 289 290 @s.coverage_level = 1 291 report = @s.report 292 293 expected = <<-EXPECTED 294The following items are not documented: 295 296# in files: 297# file.rb 298 299class C1 300end 301 302 EXPECTED 303 304 assert_equal expected, report 305 end 306 307 def test_report_class_method_documented 308 c = @tl.add_class RDoc::NormalClass, 'C' 309 c.record_location @tl 310 311 m = RDoc::AnyMethod.new nil, 'm' 312 m.record_location @tl 313 c.add_method m 314 m.comment = 'm' 315 316 @store.complete :public 317 318 report = @s.report 319 320 expected = <<-EXPECTED 321The following items are not documented: 322 323# in files: 324# file.rb 325 326class C 327end 328 EXPECTED 329 330 assert_equal expected, report 331 end 332 333 def test_report_class_module_ignore 334 c = @tl.add_class RDoc::NormalClass, 'C' 335 c.ignore 336 337 @store.complete :public 338 339 report = @s.report_class_module c 340 341 assert_nil report 342 end 343 344 def test_report_empty 345 @store.complete :public 346 347 report = @s.report 348 349 assert_equal @s.great_job, report 350 end 351 352 def test_report_method 353 c = @tl.add_class RDoc::NormalClass, 'C' 354 c.record_location @tl 355 c.add_comment 'C', @tl 356 357 m1 = RDoc::AnyMethod.new nil, 'm1' 358 m1.record_location @tl 359 c.add_method m1 360 361 m2 = RDoc::AnyMethod.new nil, 'm2' 362 m2.record_location @tl 363 c.add_method m2 364 m2.comment = 'm2' 365 366 @store.complete :public 367 368 report = @s.report 369 370 expected = <<-EXPECTED 371The following items are not documented: 372 373class C # is documented 374 375 # in file file.rb 376 def m1; end 377 378end 379 EXPECTED 380 381 assert_equal expected, report 382 end 383 384 def test_report_method_class 385 c = @tl.add_class RDoc::NormalClass, 'C' 386 c.record_location @tl 387 c.add_comment 'C', @tl 388 389 m1 = RDoc::AnyMethod.new nil, 'm1' 390 m1.record_location @tl 391 m1.singleton = true 392 c.add_method m1 393 394 m2 = RDoc::AnyMethod.new nil, 'm2' 395 m2.record_location @tl 396 m2.singleton = true 397 c.add_method m2 398 m2.comment = 'm2' 399 400 @store.complete :public 401 402 report = @s.report 403 404 expected = <<-EXPECTED 405The following items are not documented: 406 407class C # is documented 408 409 # in file file.rb 410 def self.m1; end 411 412end 413 EXPECTED 414 415 assert_equal expected, report 416 end 417 418 def test_report_method_documented 419 c = @tl.add_class RDoc::NormalClass, 'C' 420 c.record_location @tl 421 c.add_comment 'C', @tl 422 423 m = RDoc::AnyMethod.new nil, 'm' 424 m.record_location @tl 425 c.add_method m 426 m.comment = 'm' 427 428 @store.complete :public 429 430 report = @s.report 431 432 assert_equal @s.great_job, report 433 end 434 435 def test_report_method_line 436 c = @tl.add_class RDoc::NormalClass, 'C' 437 c.record_location @tl 438 c.add_comment 'C', @tl 439 440 m1 = RDoc::AnyMethod.new nil, 'm1' 441 m1.record_location @tl 442 m1.line = 4 443 c.add_method m1 444 445 @store.complete :public 446 447 assert_match '# in file file.rb:4', @s.report 448 end 449 450 def test_report_method_parameters 451 c = @tl.add_class RDoc::NormalClass, 'C' 452 c.record_location @tl 453 c.add_comment 'C', @tl 454 455 m1 = RDoc::AnyMethod.new nil, 'm1' 456 m1.record_location @tl 457 m1.params = '(p1, p2)' 458 m1.comment = 'Stuff with +p1+' 459 c.add_method m1 460 461 m2 = RDoc::AnyMethod.new nil, 'm2' 462 m2.record_location @tl 463 c.add_method m2 464 m2.comment = 'm2' 465 466 @store.complete :public 467 468 @s.coverage_level = 1 469 report = @s.report 470 471 expected = <<-EXPECTED 472The following items are not documented: 473 474class C # is documented 475 476 # in file file.rb 477 # +p2+ is not documented 478 def m1(p1, p2); end 479 480end 481 EXPECTED 482 483 assert_equal expected, report 484 end 485 486 def test_report_method_parameters_documented 487 @tl.parser = RDoc::Parser::Ruby 488 c = @tl.add_class RDoc::NormalClass, 'C' 489 c.record_location @tl 490 c.add_comment 'C', @tl 491 492 m = RDoc::AnyMethod.new nil, 'm' 493 m.record_location @tl 494 m.params = '(p1)' 495 m.comment = 'Stuff with +p1+' 496 c.add_method m 497 498 @store.complete :public 499 500 @s.coverage_level = 1 501 report = @s.report 502 503 assert_equal @s.great_job, report 504 end 505 506 def test_report_method_parameters_yield 507 c = @tl.add_class RDoc::NormalClass, 'C' 508 c.record_location @tl 509 c.add_comment 'C', @tl 510 511 m = RDoc::AnyMethod.new nil, 'm' 512 m.record_location @tl 513 m.call_seq = <<-SEQ 514m(a) { |c| ... } 515m(a, b) { |c, d| ... } 516 SEQ 517 m.comment = 'Stuff with +a+, yields +c+ for you to do stuff with' 518 c.add_method m 519 520 @store.complete :public 521 522 @s.coverage_level = 1 523 report = @s.report 524 525 expected = <<-EXPECTED 526The following items are not documented: 527 528class C # is documented 529 530 # in file file.rb 531 # +b+, +d+ is not documented 532 def m; end 533 534end 535 EXPECTED 536 537 assert_equal expected, report 538 end 539 540 def test_summary 541 c = @tl.add_class RDoc::NormalClass, 'C' 542 c.record_location @tl 543 544 m = @tl.add_module RDoc::NormalModule, 'M' 545 m.record_location @tl 546 547 a = RDoc::Attr.new nil, 'a', 'RW', nil 548 a.record_location @tl 549 c.add_attribute a 550 551 c_c = RDoc::Constant.new 'C', nil, nil 552 c_c.record_location @tl 553 c.add_constant c_c 554 555 m = RDoc::AnyMethod.new nil, 'm' 556 m.record_location @tl 557 c.add_method m 558 559 @store.complete :public 560 561 summary = @s.summary 562 summary.sub!(/Elapsed:.*/, '') 563 564 expected = <<-EXPECTED 565Files: 0 566 567Classes: 1 (1 undocumented) 568Modules: 1 (1 undocumented) 569Constants: 1 (1 undocumented) 570Attributes: 1 (1 undocumented) 571Methods: 1 (1 undocumented) 572 573Total: 5 (5 undocumented) 574 0.00% documented 575 576 EXPECTED 577 578 assert_equal summary, expected 579 end 580 581 def test_summary_level_false 582 c = @tl.add_class RDoc::NormalClass, 'C' 583 c.record_location @tl 584 585 @store.complete :public 586 587 @s.coverage_level = false 588 589 summary = @s.summary 590 summary.sub!(/Elapsed:.*/, '') 591 592 expected = <<-EXPECTED 593Files: 0 594 595Classes: 1 (1 undocumented) 596Modules: 0 (0 undocumented) 597Constants: 0 (0 undocumented) 598Attributes: 0 (0 undocumented) 599Methods: 0 (0 undocumented) 600 601Total: 1 (1 undocumented) 602 0.00% documented 603 604 EXPECTED 605 606 assert_equal summary, expected 607 end 608 609 def test_summary_level_1 610 c = @tl.add_class RDoc::NormalClass, 'C' 611 c.record_location @tl 612 c.add_comment 'C', @tl 613 614 m = RDoc::AnyMethod.new nil, 'm' 615 m.record_location @tl 616 m.params = '(p1, p2)' 617 m.comment = 'Stuff with +p1+' 618 c.add_method m 619 620 @store.complete :public 621 622 @s.coverage_level = 1 623 @s.report 624 625 summary = @s.summary 626 summary.sub!(/Elapsed:.*/, '') 627 628 expected = <<-EXPECTED 629Files: 0 630 631Classes: 1 (0 undocumented) 632Modules: 0 (0 undocumented) 633Constants: 0 (0 undocumented) 634Attributes: 0 (0 undocumented) 635Methods: 1 (0 undocumented) 636Parameters: 2 (1 undocumented) 637 638Total: 4 (1 undocumented) 639 75.00% documented 640 641 EXPECTED 642 643 assert_equal summary, expected 644 end 645 646end 647 648