1 54 package org.w3c.tidy; 55 56 import junit.framework.TestCase; 57 58 59 64 public class ReportTest extends TestCase 65 { 66 67 70 private Report report; 71 72 75 private Lexer lexer; 76 77 81 public ReportTest(String name) 82 { 83 super(name); 84 } 85 86 89 protected void setUp() throws Exception 90 { 91 super.setUp(); 92 this.report = new Report(); 93 this.lexer = new Lexer(null, new Configuration(report), this.report); 94 lexer.lines = 12; 95 lexer.columns = 34; 96 } 97 98 102 public void testGetMessageMissingEndtagFor() throws Exception 103 { 104 String message = this.report.getMessage( 105 -1, 106 lexer, 107 "missing_endtag_for", 108 new Object []{"test"}, 109 TidyMessage.Level.WARNING); 110 assertEquals("line 12 column 34 - Warning: missing </test>", message); 111 } 112 113 117 public void testGetMessageMissingEndtagBefore() throws Exception 118 { 119 String message = this.report.getMessage( 120 -1, 121 lexer, 122 "missing_endtag_before", 123 new Object []{"test", "bee"}, 124 TidyMessage.Level.WARNING); 125 assertEquals("line 12 column 34 - Warning: missing </test> before bee", message); 126 } 127 128 132 public void testGetMessageDiscardingUnexpected() throws Exception 133 { 134 String message = this.report.getMessage( 135 -1, 136 lexer, 137 "discarding_unexpected", 138 new Object []{"test"}, 139 TidyMessage.Level.WARNING); 140 assertEquals("line 12 column 34 - Warning: discarding unexpected test", message); 141 } 142 143 147 public void testGetMessageNestedEmphasis() throws Exception 148 { 149 String message = this.report.getMessage( 150 -1, 151 lexer, 152 "nested_emphasis", 153 new Object []{"test"}, 154 TidyMessage.Level.INFO); 155 assertEquals("line 12 column 34 - nested emphasis test", message); 156 } 157 158 162 public void testGetMessageCoerceToEndtag() throws Exception 163 { 164 String message = this.report.getMessage( 165 -1, 166 lexer, 167 "coerce_to_endtag", 168 new Object []{"test"}, 169 TidyMessage.Level.INFO); 170 assertEquals("line 12 column 34 - <test> is probably intended as </test>", message); 171 } 172 173 177 public void testGetMessageNonMatchingEndtag() throws Exception 178 { 179 String message = this.report.getMessage( 180 -1, 181 lexer, 182 "non_matching_endtag", 183 new Object []{"<test>", "bee"}, 184 TidyMessage.Level.WARNING); 185 assertEquals("line 12 column 34 - Warning: replacing unexpected <test> by </bee>", message); 186 } 187 188 192 public void testGetMessageTagNonAllowedIn() throws Exception 193 { 194 String message = this.report.getMessage( 195 -1, 196 lexer, 197 "tag_not_allowed_in", 198 new Object []{"<test>", "bee"}, 199 TidyMessage.Level.WARNING); 200 assertEquals("line 12 column 34 - Warning: <test> isn't allowed in <bee> elements", message); 201 } 202 203 207 public void testGetMessageDoctypeAfterTags() throws Exception 208 { 209 String message = this.report.getMessage(-1, lexer, "doctype_after_tags", null, TidyMessage.Level.WARNING); 210 assertEquals("line 12 column 34 - Warning: <!DOCTYPE> isn't allowed after elements", message); 211 } 212 213 217 public void testGetMessageMissingStarttag() throws Exception 218 { 219 String message = this.report.getMessage( 220 -1, 221 lexer, 222 "missing_starttag", 223 new Object []{"test"}, 224 TidyMessage.Level.WARNING); 225 assertEquals("line 12 column 34 - Warning: missing <test>", message); 226 } 227 228 232 public void testGetMessageUsingBrInPlaceOf() throws Exception 233 { 234 String message = this.report.getMessage( 235 -1, 236 lexer, 237 "using_br_inplace_of", 238 new Object []{"test"}, 239 TidyMessage.Level.WARNING); 240 assertEquals("line 12 column 34 - Warning: using <br> in place of test", message); 241 } 242 243 247 public void testGetMessageInsertingTag() throws Exception 248 { 249 String message = this.report.getMessage( 250 -1, 251 lexer, 252 "inserting_tag", 253 new Object []{"test"}, 254 TidyMessage.Level.WARNING); 255 assertEquals("line 12 column 34 - Warning: inserting implicit <test>", message); 256 } 257 258 262 public void testGetMessageCantBeNested() throws Exception 263 { 264 String message = this.report.getMessage( 265 -1, 266 lexer, 267 "cant_be_nested", 268 new Object []{"<test>"}, 269 TidyMessage.Level.WARNING); 270 assertEquals("line 12 column 34 - Warning: <test> can't be nested", message); 271 } 272 273 277 public void testGetMessageProprietaryElement() throws Exception 278 { 279 String message = this.report.getMessage( 280 -1, 281 lexer, 282 "proprietary_element", 283 new Object []{"<test>"}, 284 TidyMessage.Level.WARNING); 285 assertEquals("line 12 column 34 - Warning: <test> is not approved by W3C", message); 286 } 287 288 292 public void testGetMessageObsoleteElement() throws Exception 293 { 294 String message = this.report.getMessage( 295 -1, 296 lexer, 297 "obsolete_element", 298 new Object []{"<test>", "<bee>"}, 299 TidyMessage.Level.WARNING); 300 assertEquals("line 12 column 34 - Warning: replacing obsolete element <test> by <bee>", message); 301 } 302 303 307 public void testGetMessageReplacingElement() throws Exception 308 { 309 String message = this.report.getMessage( 310 -1, 311 lexer, 312 "replacing_element", 313 new Object []{"<test>", "<bee>"}, 314 TidyMessage.Level.WARNING); 315 assertEquals("line 12 column 34 - Warning: replacing element <test> by <bee>", message); 316 } 317 318 322 public void testGetMessageTrimEmptyElement() throws Exception 323 { 324 String message = this.report.getMessage( 325 -1, 326 lexer, 327 "trim_empty_element", 328 new Object []{"<test>"}, 329 TidyMessage.Level.WARNING); 330 assertEquals("line 12 column 34 - Warning: trimming empty <test>", message); 331 } 332 333 337 public void testGetMessageMissingTitleElement() throws Exception 338 { 339 String message = this.report.getMessage(-1, lexer, "missing_title_element", null, TidyMessage.Level.WARNING); 340 assertEquals("line 12 column 34 - Warning: inserting missing 'title' element", message); 341 } 342 343 347 public void testGetMessageIllegalNesting() throws Exception 348 { 349 String message = this.report.getMessage( 350 -1, 351 lexer, 352 "illegal_nesting", 353 new Object []{"<test>"}, 354 TidyMessage.Level.WARNING); 355 assertEquals("line 12 column 34 - Warning: <test> shouldn't be nested", message); 356 } 357 358 362 public void testGetMessageNoframesContent() throws Exception 363 { 364 String message = this.report.getMessage( 365 -1, 366 lexer, 367 "noframes_content", 368 new Object []{"<test>"}, 369 TidyMessage.Level.WARNING); 370 assertEquals("line 12 column 34 - Warning: <test> not inside 'noframes' element", message); 371 } 372 373 377 public void testGetMessageInconsistentVersion() throws Exception 378 { 379 String message = this.report.getMessage(-1, lexer, "inconsistent_version", null, TidyMessage.Level.WARNING); 380 assertEquals("line 12 column 34 - Warning: html doctype doesn't match content", message); 381 } 382 383 387 public void testGetMessageMalformedDoctype() throws Exception 388 { 389 String message = this.report.getMessage(-1, lexer, "malformed_doctype", null, TidyMessage.Level.WARNING); 390 assertEquals("line 12 column 34 - Warning: expected \"html PUBLIC\" or \"html SYSTEM\"", message); 391 } 392 393 397 public void testGetMessageContentAfterBody() throws Exception 398 { 399 String message = this.report.getMessage(-1, lexer, "content_after_body", null, TidyMessage.Level.WARNING); 400 assertEquals("line 12 column 34 - Warning: content occurs after end of body", message); 401 } 402 403 407 public void testGetMessageMalformedComment() throws Exception 408 { 409 String message = this.report.getMessage(-1, lexer, "malformed_comment", null, TidyMessage.Level.WARNING); 410 assertEquals("line 12 column 34 - Warning: adjacent hyphens within comment", message); 411 } 412 413 417 public void testGetMessageBadCommentChars() throws Exception 418 { 419 String message = this.report.getMessage(-1, lexer, "bad_comment_chars", null, TidyMessage.Level.WARNING); 420 assertEquals("line 12 column 34 - Warning: expecting -- or >", message); 421 } 422 423 427 public void testGetMessageBadXmlComment() throws Exception 428 { 429 String message = this.report.getMessage(-1, lexer, "bad_xml_comment", null, TidyMessage.Level.WARNING); 430 assertEquals("line 12 column 34 - Warning: XML comments can't contain --", message); 431 } 432 433 437 public void testGetMessageBadCdataComment() throws Exception 438 { 439 String message = this.report.getMessage(-1, lexer, "bad_cdata_content", null, TidyMessage.Level.WARNING); 440 assertEquals("line 12 column 34 - Warning: '<' + '/' + letter not allowed here", message); 441 } 442 443 447 public void testGetMessageInconsistentNamespace() throws Exception 448 { 449 String message = this.report.getMessage(-1, lexer, "inconsistent_namespace", null, TidyMessage.Level.WARNING); 450 assertEquals("line 12 column 34 - Warning: html namespace doesn't match content", message); 451 } 452 453 457 public void testGetMessageDtypeNotUpperCase() throws Exception 458 { 459 String message = this.report.getMessage(-1, lexer, "dtype_not_upper_case", null, TidyMessage.Level.WARNING); 460 assertEquals("line 12 column 34 - Warning: SYSTEM, PUBLIC, W3C, DTD, EN must be upper case", message); 461 } 462 463 467 public void testGetMessageUnexpectedEndOfFile() throws Exception 468 { 469 String message = this.report.getMessage( 470 -1, 471 lexer, 472 "unexpected_end_of_file", 473 new Object []{"<test>"}, 474 TidyMessage.Level.WARNING); 475 assertEquals("line 12 column 34 - Warning: end of file while parsing attributes <test>", message); 476 } 477 478 482 public void testGetMessageSuspectedMissingQuote() throws Exception 483 { 484 String message = this.report.getMessage(-1, lexer, "suspected_missing_quote", null, TidyMessage.Level.ERROR); 485 assertEquals("line 12 column 34 - Error: missing quotemark for attribute value", message); 486 } 487 488 492 public void testGetMessageDuplicateFrameset() throws Exception 493 { 494 String message = this.report.getMessage(-1, lexer, "duplicate_frameset", null, TidyMessage.Level.ERROR); 495 assertEquals("line 12 column 34 - Error: repeated FRAMESET element", message); 496 } 497 498 502 public void testGetMessageUnknownElement() throws Exception 503 { 504 String message = this.report.getMessage( 505 -1, 506 lexer, 507 "unknown_element", 508 new Object []{"<test>"}, 509 TidyMessage.Level.ERROR); 510 assertEquals("line 12 column 34 - Error: <test> is not recognized!", message); 511 } 512 513 517 public void testGetMessageUnexpectedEndtag() throws Exception 518 { 519 String message = this.report.getMessage( 520 -1, 521 lexer, 522 "unexpected_endtag", 523 new Object []{"test"}, 524 TidyMessage.Level.ERROR); 525 assertEquals("line 12 column 34 - Error: unexpected </test>", message); 526 } 527 528 532 public void testGetMessageUnexpectedEndtagIn() throws Exception 533 { 534 String message = this.report.getMessage( 535 -1, 536 lexer, 537 "unexpected_endtag_in", 538 new Object []{"test", "bee"}, 539 TidyMessage.Level.ERROR); 540 assertEquals("line 12 column 34 - Error: unexpected </test> in <bee>", message); 541 } 542 543 547 public void testGetMessageTooManyElements() throws Exception 548 { 549 String message = this.report.getMessage( 550 -1, 551 lexer, 552 "too_many_elements", 553 new Object []{"<test>"}, 554 TidyMessage.Level.WARNING); 555 assertEquals("line 12 column 34 - Warning: too many <test> elements", message); 556 } 557 558 562 public void testGetMessageTooManyElementsIn() throws Exception 563 { 564 String message = this.report.getMessage( 565 -1, 566 lexer, 567 "too_many_elements_in", 568 new Object []{"<test>", "bee"}, 569 TidyMessage.Level.WARNING); 570 assertEquals("line 12 column 34 - Warning: too many <test> elements in <bee>", message); 571 } 572 573 577 public void testGetMessageUnknownAttribute() throws Exception 578 { 579 String message = this.report.getMessage( 580 -1, 581 lexer, 582 "unknown_attribute", 583 new Object []{"test"}, 584 TidyMessage.Level.WARNING); 585 assertEquals("line 12 column 34 - Warning: unknown attribute \"test\"", message); 586 } 587 588 592 public void testGetMessageMissingAttribute() throws Exception 593 { 594 String message = this.report.getMessage( 595 -1, 596 lexer, 597 "missing_attribute", 598 new Object []{"<test>", "bee"}, 599 TidyMessage.Level.WARNING); 600 assertEquals("line 12 column 34 - Warning: <test> lacks \"bee\" attribute", message); 601 } 602 603 607 public void testGetMessageMissingAttrValue() throws Exception 608 { 609 String message = this.report.getMessage( 610 -1, 611 lexer, 612 "missing_attr_value", 613 new Object []{"<test>", "bee"}, 614 TidyMessage.Level.WARNING); 615 assertEquals("line 12 column 34 - Warning: <test> attribute \"bee\" lacks value", message); 616 } 617 618 622 public void testGetMessageMissingImagemap() throws Exception 623 { 624 String message = this.report.getMessage( 625 -1, 626 lexer, 627 "missing_imagemap", 628 new Object []{"<test>"}, 629 TidyMessage.Level.WARNING); 630 assertEquals("line 12 column 34 - Warning: <test> should use client-side image map", message); 631 } 632 633 637 public void testGetMessageBadAttributeValue() throws Exception 638 { 639 String message = this.report.getMessage( 640 -1, 641 lexer, 642 "bad_attribute_value", 643 new Object []{"<test>", "bee", "ant"}, 644 TidyMessage.Level.WARNING); 645 assertEquals("line 12 column 34 - Warning: <test> attribute \"bee\" has invalid value \"ant\"", message); 646 } 647 648 652 public void testGetMessageXmlAttributeValue() throws Exception 653 { 654 String message = this.report.getMessage( 655 -1, 656 lexer, 657 "xml_attribute_value", 658 new Object []{"<test>", "bee"}, 659 TidyMessage.Level.WARNING); 660 assertEquals("line 12 column 34 - Warning: <test> has XML attribute \"bee\"", message); 661 } 662 663 667 public void testGetMessageUnexpectedGt() throws Exception 668 { 669 String message = this.report.getMessage( 670 -1, 671 lexer, 672 "unexpected_gt", 673 new Object []{"<test>"}, 674 TidyMessage.Level.ERROR); 675 assertEquals("line 12 column 34 - Error: <test> missing '>' for end of tag", message); 676 } 677 678 682 public void testGetMessageUnexpectedQuotemark() throws Exception 683 { 684 String message = this.report.getMessage( 685 -1, 686 lexer, 687 "unexpected_quotemark", 688 new Object []{"<test>"}, 689 TidyMessage.Level.WARNING); 690 assertEquals("line 12 column 34 - Warning: <test> unexpected or duplicate quote mark", message); 691 } 692 693 697 public void testGetMessageRepeatedAttribute() throws Exception 698 { 699 String message = this.report.getMessage( 700 -1, 701 lexer, 702 "repeated_attribute", 703 new Object []{"<test>", "bee", "ant"}, 704 TidyMessage.Level.WARNING); 705 assertEquals( 706 "line 12 column 34 - Warning: <test> dropping value \"bee\" for repeated attribute \"ant\"", 707 message); 708 } 709 710 714 public void testGetMessageProprietaryAttrValue() throws Exception 715 { 716 String message = this.report.getMessage( 717 -1, 718 lexer, 719 "proprietary_attr_value", 720 new Object []{"<test>", "bee"}, 721 TidyMessage.Level.WARNING); 722 assertEquals("line 12 column 34 - Warning: <test> proprietary attribute value \"bee\"", message); 723 } 724 725 729 public void testGetMessageProprietaryAttribute() throws Exception 730 { 731 String message = this.report.getMessage( 732 -1, 733 lexer, 734 "proprietary_attribute", 735 new Object []{"<test>", "bee"}, 736 TidyMessage.Level.WARNING); 737 assertEquals("line 12 column 34 - Warning: <test> proprietary attribute \"bee\"", message); 738 } 739 740 744 public void testGetMessageIdNameMismatch() throws Exception 745 { 746 String message = this.report.getMessage( 747 -1, 748 lexer, 749 "id_name_mismatch", 750 new Object []{"<test>"}, 751 TidyMessage.Level.WARNING); 752 assertEquals("line 12 column 34 - Warning: <test> id and name attribute value mismatch", message); 753 } 754 755 759 public void testGetMessageMissingDoctype() throws Exception 760 { 761 String message = this.report.getMessage(-1, lexer, "missing_doctype", null, TidyMessage.Level.WARNING); 762 assertEquals("line 12 column 34 - Warning: missing <!DOCTYPE> declaration", message); 763 } 764 765 769 public void testGetMessageDoctypeGiven() throws Exception 770 { 771 String message = this.report.getMessage( 772 -1, 773 lexer, 774 "doctype_given", 775 new Object []{"test", "bee"}, 776 TidyMessage.Level.SUMMARY); 777 assertEquals("test: Doctype given is \"bee\"", message); 778 } 779 780 784 public void testGetMessageReportVersion() throws Exception 785 { 786 String message = this.report.getMessage( 787 -1, 788 lexer, 789 "report_version", 790 new Object []{"test", "bee"}, 791 TidyMessage.Level.SUMMARY); 792 assertEquals("test: Document content looks like bee", message); 793 } 794 795 799 public void testGetMessageNumWarning() throws Exception 800 { 801 String message = this.report.getMessage( 802 -1, 803 lexer, 804 "num_warnings", 805 new Object []{new Integer (0), new Integer (33)}, 806 TidyMessage.Level.SUMMARY); 807 assertEquals("no warnings, 33 errors were found!", message); 808 } 809 810 } | Popular Tags |