1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
|
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = test_RichText.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
# by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') if __FILE__ == $0
require 'test/unit'
require 'taskjuggler/RichText'
require 'taskjuggler/RichText/FunctionHandler'
require 'taskjuggler/MessageHandler'
class RTFDummy < TaskJuggler::RichTextFunctionHandler
def initialize()
super('dummy')
@blockFunction = true
end
# Return a XMLElement tree that represents the blockfunc in HTML code.
def to_html(args)
TaskJuggler::XMLElement.new('blockfunc:dummy', args, true)
end
end
class TestRichText < Test::Unit::TestCase
def setup
end
def teardown
end
def test_empty
inp = ''
tagged = "<div></div>\n"
str = "\n"
html = "<div></div>\n"
assert_outputs(inp, tagged, str, html)
assert_equal(true, newRichText(inp).empty?, 'Empty string')
assert_equal(true, newRichText("\n").empty?, '\n')
assert_equal(true, newRichText("\n \n").empty?, '\n \n')
assert_equal(false, newRichText("foo").empty?, 'foo')
end
def test_one_word
inp = "foo"
tagged = "<div>[foo]</div>\n"
str = "foo\n"
html= "<div>foo</div>\n"
assert_outputs(inp, tagged, str, html)
end
def test_two_words
inp = "foo bar"
tagged = "<div>[foo] [bar]</div>\n"
str = "foo bar\n"
html = "<div>foo bar</div>\n"
assert_outputs(inp, tagged, str, html)
end
def test_paragraph
inp = <<'EOT'
A paragraph may span multiple
lines of text. Single line breaks
are ignored.
Only 2 successive newlines end the paragraph.
I hope this example is
clear
now.
EOT
tagged = <<'EOT'
<div><p>[A] [paragraph] [may] [span] [multiple] [lines] [of] [text.] [Single] [line] [breaks] [are] [ignored.]</p>
<p>[Only] [2] [successive] [newlines] [end] [the] [paragraph.]</p>
<p>[I] [hope] [this] [example] [is] [clear] [now.]</p>
</div>
EOT
str = <<'EOT'
A paragraph may span multiple lines of text. Single line breaks are ignored.
Only 2 successive newlines end the paragraph.
I hope this example is clear now.
EOT
html = <<'EOT'
<div>
<p>A paragraph may span multiple lines of text. Single line breaks are ignored.</p>
<p>Only 2 successive newlines end the paragraph.</p>
<p>I hope this example is clear now.</p>
</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_hline
inp = <<'EOT'
----
Line above and below
----
== A heading ==
----
----
----
Another bit of text.
----
EOT
tagged = <<'EOT'
<div><hr>----</hr>
<p>[Line] [above] [and] [below]</p>
<hr>----</hr>
<h1>1 [A] [heading]</h1>
<hr>----</hr>
<hr>----</hr>
<hr>----</hr>
<p>[Another] [bit] [of] [text.]</p>
<hr>----</hr>
</div>
EOT
str = <<'EOT'
------------------------------------------------------------
Line above and below
------------------------------------------------------------
1) A heading
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Another bit of text.
------------------------------------------------------------
EOT
html = <<'EOT'
<div>
<hr/>
<p>Line above and below</p>
<hr/>
<h1 id="A_heading">1 A heading</h1>
<hr/>
<hr/>
<hr/>
<p>Another bit of text.</p>
<hr/>
</div>
EOT
assert_outputs(inp, tagged, str, html, 60)
end
def test_italic
inp = "This is a text with ''italic words '' in it."
tagged = <<'EOT'
<div>[This] [is] [a] [text] [with] <i>[italic] [words]</i> [in] [it.]</div>
EOT
str = <<'EOT'
This is a text with italic words in it.
EOT
html = <<'EOT'
<div>This is a text with <i>italic words</i> in it.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_bold
inp = "This is a text with ''' bold words''' in it."
tagged = <<'EOT'
<div>[This] [is] [a] [text] [with] <b>[bold] [words]</b> [in] [it.]</div>
EOT
str = <<'EOT'
This is a text with bold words in it.
EOT
html = <<'EOT'
<div>This is a text with <b>bold words</b> in it.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_code
inp = "This is a text with ''''monospaced words'''' in it."
tagged = <<'EOT'
<div>[This] [is] [a] [text] [with] <code>[monospaced] [words]</code> [in] [it.]</div>
EOT
str = <<'EOT'
This is a text with monospaced words in it.
EOT
html = <<'EOT'
<div>This is a text with <code>monospaced words</code> in it.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_boldAndItalic
inp = <<'EOT'
This is a text with some '''bold words''', some ''italic'' words and some
'''''bold and italic''''' words in it.
EOT
tagged = <<'EOT'
<div>[This] [is] [a] [text] [with] [some] <b>[bold] [words]</b>[,] [some] <i>[italic]</i> [words] [and] [some] <b><i>[bold] [and] [italic]</i></b> [words] [in] [it.]</div>
EOT
str = <<'EOT'
This is a text with some bold words, some italic words and some bold and italic words in it.
EOT
html = <<'EOT'
<div>This is a text with some <b>bold words</b>, some <i>italic</i> words and some <b><i>bold and italic</i></b> words in it.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_ref
inp = <<'EOT'
This is a reference [[item]].
For more info see [[manual|the user manual]].
EOT
tagged = <<'EOT'
<div>[This] [is] [a] [reference] <ref data="item">[item]</ref>[.] [For] [more] [info] [see] <ref data="manual">[the user manual]</ref>[.]</div>
EOT
str = <<'EOT'
This is a reference item. For more info see the user manual.
EOT
html = <<'EOT'
<div>This is a reference <a href="item.html">item</a>. For more info see <a href="manual.html">the user manual</a>.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_img
inp = <<'EOT'
This is an [[File:image.jpg]].
For more info see [[File:icon.png|alt=this image]].
EOT
tagged = <<'EOT'
<div>[This] [is] [an] <img file="image.jpg"/>[.] [For] [more] [info] [see] <img file="icon.png"/>[.]</div>
EOT
str = <<'EOT'
This is an . For more info see this image.
EOT
html = <<'EOT'
<div>This is an <object data="image.jpg" type="image/jpg"></object>. For more info see <object alt="this image" data="icon.png" type="image/png"></object>.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_href
inp = <<'EOT'
This is a reference [http://www.taskjuggler.org].
For more info see [http://www.taskjuggler.org the TaskJuggler site].
EOT
tagged = <<'EOT'
<div>[This] [is] [a] [reference] <a href="http://www.taskjuggler.org" target="_blank">[http://www.taskjuggler.org]</a>[.] [For] [more] [info] [see] <a href="http://www.taskjuggler.org" target="_blank">[the] [TaskJuggler] [site]</a>[.]</div>
EOT
str = <<'EOT'
This is a reference http://www.taskjuggler.org. For more info see the TaskJuggler site.
EOT
html = <<'EOT'
<div>This is a reference <a href="http://www.taskjuggler.org" target="_blank">http://www.taskjuggler.org</a>. For more info see <a href="http://www.taskjuggler.org" target="_blank">the TaskJuggler site</a>.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_hrefWithWrappedLines
inp = <<'EOT'
A [http://www.taskjuggler.org
multi line] reference.
EOT
tagged = <<'EOT'
<div>[A] <a href="http://www.taskjuggler.org" target="_blank">[multi] [line]</a> [reference.]</div>
EOT
str = <<'EOT'
A multi line reference.
EOT
html = <<'EOT'
<div>A <a href="http://www.taskjuggler.org" target="_blank">multi line</a> reference.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_headline
inp = <<'EOT'
= This is not a headline
== This is level 1 ==
=== This is level 2 ===
==== This is level 3 ====
===== This is level 4 =====
EOT
tagged = <<'EOT'
<div><p>[=] [This] [is] [not] [a] [headline]</p>
<h1>1 [This] [is] [level] [1]</h1>
<h2>1.1 [This] [is] [level] [2]</h2>
<h3>1.1.1 [This] [is] [level] [3]</h3>
<h4>1.1.1.1 [This] [is] [level] [4]</h4>
</div>
EOT
str = <<'EOT'
= This is not a headline
1) This is level 1
1.1) This is level 2
1.1.1) This is level 3
1.1.1.1) This is level 4
EOT
html = <<'EOT'
<div>
<p>= This is not a headline</p>
<h1 id="This_is_level_1">1 This is level 1</h1>
<h2 id="This_is_level_2">1.1 This is level 2</h2>
<h3 id="This_is_level_3">1.1.1 This is level 3</h3>
<h4 id="This_is_level_4">1.1.1.1 This is level 4</h4>
</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_bullet
inp = <<'EOT'
* This is a bullet item
** This is a level 2 bullet item
*** This is a level 3 bullet item
**** This is a level 4 bullet item
EOT
tagged = <<'EOT'
<div><ul><li>* [This] [is] [a] [bullet] [item]</li>
<ul><li> * [This] [is] [a] [level] [2] [bullet] [item]</li>
<ul><li> * [This] [is] [a] [level] [3] [bullet] [item]</li>
<ul><li> * [This] [is] [a] [level] [4] [bullet] [item]</li>
</ul></ul></ul></ul></div>
EOT
str = <<'EOT'
* This is a bullet item
* This is a level 2 bullet item
* This is a level 3 bullet item
* This is a level 4 bullet item
EOT
html = <<'EOT'
<div><ul>
<li>This is a bullet item</li>
<ul>
<li>This is a level 2 bullet item</li>
<ul>
<li>This is a level 3 bullet item</li>
<ul><li>This is a level 4 bullet item</li></ul>
</ul>
</ul>
</ul></div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_number
inp = <<'EOT'
# This is item 1
# This is item 2
# This is item 3
Normal text.
# This is item 1
## This is item 1.1
## This is item 1.2
## This is item 1.3
# This is item 2
## This is item 2.1
## This is item 2.2
### This is item 2.2.1
### This is item 2.2.2
#### This is item 2.2.2.1
# This is item 3
## This is item 3.1
### This is item 3.1.1
# This is item 4
### This is item 4.0.1
Normal text.
# This is item 1
EOT
tagged = <<'EOT'
<div><ol><li>1 [This] [is] [item] [1]</li>
<li>2 [This] [is] [item] [2]</li>
<li>3 [This] [is] [item] [3]</li>
</ol><p>[Normal] [text.]</p>
<ol><li>1 [This] [is] [item] [1]</li>
<ol><li>1.1 [This] [is] [item] [1.1]</li>
<li>1.2 [This] [is] [item] [1.2]</li>
<li>1.3 [This] [is] [item] [1.3]</li>
</ol><li>2 [This] [is] [item] [2]</li>
<ol><li>2.1 [This] [is] [item] [2.1]</li>
<li>2.2 [This] [is] [item] [2.2]</li>
<ol><li>2.2.1 [This] [is] [item] [2.2.1]</li>
<li>2.2.2 [This] [is] [item] [2.2.2]</li>
<ol><li>2.2.2.1 [This] [is] [item] [2.2.2.1]</li>
</ol></ol></ol><li>3 [This] [is] [item] [3]</li>
<ol><li>3.1 [This] [is] [item] [3.1]</li>
<ol><li>3.1.1 [This] [is] [item] [3.1.1]</li>
</ol></ol><li>4 [This] [is] [item] [4]</li>
<ol><ol><li>4.0.1 [This] [is] [item] [4.0.1]</li>
</ol></ol></ol><p>[Normal] [text.]</p>
<ol><li>1 [This] [is] [item] [1]</li>
</ol></div>
EOT
str = <<'EOT'
1. This is item 1
2. This is item 2
3. This is item 3
Normal text.
1. This is item 1
1.1 This is item 1.1
1.2 This is item 1.2
1.3 This is item 1.3
2. This is item 2
2.1 This is item 2.1
2.2 This is item 2.2
2.2.1 This is item 2.2.1
2.2.2 This is item 2.2.2
2.2.2.1 This is item 2.2.2.1
3. This is item 3
3.1 This is item 3.1
3.1.1 This is item 3.1.1
4. This is item 4
4.0.1 This is item 4.0.1
Normal text.
1. This is item 1
EOT
html = <<'EOT'
<div>
<ol>
<li>This is item 1</li>
<li>This is item 2</li>
<li>This is item 3</li>
</ol>
<p>Normal text.</p>
<ol>
<li>This is item 1</li>
<ol>
<li>This is item 1.1</li>
<li>This is item 1.2</li>
<li>This is item 1.3</li>
</ol>
<li>This is item 2</li>
<ol>
<li>This is item 2.1</li>
<li>This is item 2.2</li>
<ol>
<li>This is item 2.2.1</li>
<li>This is item 2.2.2</li>
<ol><li>This is item 2.2.2.1</li></ol>
</ol>
</ol>
<li>This is item 3</li>
<ol>
<li>This is item 3.1</li>
<ol><li>This is item 3.1.1</li></ol>
</ol>
<li>This is item 4</li>
<ol><ol><li>This is item 4.0.1</li></ol></ol>
</ol>
<p>Normal text.</p>
<ol><li>This is item 1</li></ol>
</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_pre
inp = <<'EOT'
#include <stdin.h>
main() {
printf("Hello, world!\n")
}
Some normal text.
* A
bullet
item
Some code
More text.
EOT
tagged = <<'EOT'
<div><pre>#include <stdin.h>
main() {
printf("Hello, world!\n")
}
</pre>
<p>[Some] [normal] [text.]</p>
<ul><li>* [A] [bullet] [item]</li>
</ul><pre>Some code
</pre>
<p>[More] [text.]</p>
</div>
EOT
str = <<'EOT'
#include <stdin.h>
main() {
printf("Hello, world!\n")
}
Some normal text.
* A bullet item
Some code
More text.
EOT
html = <<'EOT'
<div>
<div codesection="1"><pre codesection="1">#include <stdin.h>
main() {
printf("Hello, world!\n")
}
</pre></div>
<p>Some normal text.</p>
<ul><li>A bullet item</li></ul>
<div codesection="1"><pre codesection="1">Some code
</pre></div>
<p>More text.</p>
</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_mix
inp = <<'EOT'
== This the first section ==
=== This is the section 1.1 ===
Not sure what to put here. Maybe
just some silly text.
* A bullet
** Another bullet
# A number item
* A bullet
## Number 0.1, I guess
== Section 2 ==
* Starts with bullets
* ...
Some more text. And we're done.
EOT
tagged = <<'EOT'
<div><h1>1 [This] [the] [first] [section]</h1>
<h2>1.1 [This] [is] [the] [section] [1.1]</h2>
<p>[Not] [sure] [what] [to] [put] [here.] [Maybe] [just] [some] [silly] [text.]</p>
<ul><li>* [A] [bullet]</li>
<ul><li> * [Another] [bullet]</li>
</ul></ul><ol><li>1 [A] [number] [item]</li>
</ol><ul><li>* [A] [bullet]</li>
</ul><ol><ol><li>0.1 [Number] [0.1,] [I] [guess]</li>
</ol></ol><h1>2 [Section] [2]</h1>
<ul><li>* [Starts] [with] [bullets]</li>
<li>* [...]</li>
</ul><p>[Some] [more] [text.] [And] [we]['re] [done.]</p>
</div>
EOT
str = <<'EOT'
1) This the first section
1.1) This is the section 1.1
Not sure what to put here. Maybe just some silly text.
* A bullet
* Another bullet
1. A number item
* A bullet
0.1 Number 0.1, I guess
2) Section 2
* Starts with bullets
* ...
Some more text. And we're done.
EOT
html = <<'EOT'
<div>
<h1 id="This_the_first_section">1 This the first section</h1>
<h2 id="This_is_the_section_11">1.1 This is the section 1.1</h2>
<p>Not sure what to put here. Maybe just some silly text.</p>
<ul>
<li>A bullet</li>
<ul><li>Another bullet</li></ul>
</ul>
<ol><li>A number item</li></ol>
<ul><li>A bullet</li></ul>
<ol><ol><li>Number 0.1, I guess</li></ol></ol>
<h1 id="Section_2">2 Section 2</h1>
<ul>
<li>Starts with bullets</li>
<li>...</li>
</ul>
<p>Some more text. And we're done.</p>
</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_htmlblob
inp = <<'EOT'
A <html>raw foo
bar</html> blob.
EOT
tagged = <<'EOT'
<div>[A] <html>raw foo
bar</html> [blob.]</div>
EOT
str = <<'EOT'
A blob.
EOT
html = <<'EOT'
<div>A raw foo
bar blob.</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_nowiki
inp = <<'EOT'
== This the first section ==
=== This is the section 1.1 ===
Not sure <nowiki>''what'' to</nowiki> put here. Maybe
just some silly text.
* A bullet
** Another bullet
# A number item
* A bullet<nowiki>
## Number 0.1, I guess
== Section 2 ==</nowiki>
* Starts with bullets
* ...
Some more text. And we're done.
EOT
tagged = <<'EOT'
<div><h1>1 [This] [the] [first] [section]</h1>
<h2>1.1 [This] [is] [the] [section] [1.1]</h2>
<p>[Not] [sure] [''what''] [to] [put] [here.] [Maybe] [just] [some] [silly] [text.]</p>
<ul><li>* [A] [bullet]</li>
<ul><li> * [Another] [bullet]</li>
</ul></ul><ol><li>1 [A] [number] [item]</li>
</ol><ul><li>* [A] [bullet]</li>
</ul><p>[##] [Number] [0.1,] [I] [guess]</p>
<p>[==] [Section] [2] [==]</p>
<ul><li>* [Starts] [with] [bullets]</li>
<li>* [...]</li>
</ul><p>[Some] [more] [text.] [And] [we]['re] [done.]</p>
</div>
EOT
str = <<'EOT'
1) This the first section
1.1) This is the section 1.1
Not sure ''what'' to put here. Maybe just some silly text.
* A bullet
* Another bullet
1. A number item
* A bullet
## Number 0.1, I guess
== Section 2 ==
* Starts with bullets
* ...
Some more text. And we're done.
EOT
html = <<'EOT'
<div>
<h1 id="This_the_first_section">1 This the first section</h1>
<h2 id="This_is_the_section_11">1.1 This is the section 1.1</h2>
<p>Not sure ''what'' to put here. Maybe just some silly text.</p>
<ul>
<li>A bullet</li>
<ul><li>Another bullet</li></ul>
</ul>
<ol><li>A number item</li></ol>
<ul><li>A bullet</li></ul>
<p>## Number 0.1, I guess</p>
<p>== Section 2 ==</p>
<ul>
<li>Starts with bullets</li>
<li>...</li>
</ul>
<p>Some more text. And we're done.</p>
</div>
EOT
assert_outputs(inp, tagged, str, html)
end
def test_hline_and_link
inp = <<EOT
----
[[foo|bar]]
EOT
tagged = <<EOT
<div><hr>----</hr>
<p><ref data=\"foo\">[bar]</ref></p>
</div>
EOT
str = <<EOT
------------------------------------------------------------
bar
EOT
html = "<div>\n <hr/>\n <p><a href=\"foo.html\">bar</a></p>\n</div>\n"
assert_outputs(inp, tagged, str, html, 60)
end
def test_blockFunction
inp = <<'EOT'
<[dummy id="foo" arg1="bar"]>
=== Header ===
<[dummy arg1="A \"good\" day"]>
some text
<[dummy]>
EOT
tagged = <<'EOT'
<div><blockfunc:dummy arg1="bar" id="foo"/><h2>0.1 [Header]</h2>
<blockfunc:dummy arg1="A \"good\" day"/><p>[some] [text]</p>
<blockfunc:dummy/></div>
EOT
str = <<EOT
0.1) Header
some text
EOT
html = <<'EOT'
<div>
<blockfunc:dummy arg1="bar" id="foo"/>
<h2 id="Header">0.1 Header</h2>
<blockfunc:dummy arg1="A \"good\" day"/>
<p>some text</p>
<blockfunc:dummy/>
</div>
EOT
assert_outputs(inp, tagged, str, html, 60)
end
def test_stringLineWrapping
inp = <<EOT
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
----
EOT
# Check ASCII output.
rt = newRichText(inp)
rt.lineWidth = 60
out = rt.to_s + "\n"
ref = <<EOT
The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog. The quick brown fox jumps over the lazy dog.
------------------------------------------------------------
EOT
match(ref, out)
inp = <<EOT
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
----
EOT
# Check ASCII output.
rt = newRichText(inp)
rt.lineWidth = 60
out = rt.to_s + "\n"
ref = <<EOT
The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog. The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
------------------------------------------------------------
EOT
match(ref, out)
inp = <<EOT
The_quick_brown_fox_jumps_over_the_lazy_dog.
The_quick_brown_fox_jumps_over_the_lazy_dog.
The_quick_brown_fox_jumps_over_the_lazy_dog.
----
EOT
# Check ASCII output.
rt = newRichText(inp)
rt.lineWidth = 60
out = rt.to_s + "\n"
ref = <<EOT
The_quick_brown_fox_jumps_over_the_lazy_dog.
The_quick_brown_fox_jumps_over_the_lazy_dog.
The_quick_brown_fox_jumps_over_the_lazy_dog.
------------------------------------------------------------
EOT
match(ref, out)
inp = <<EOT
The_quick_brown_fox_jumps_over_the_lazy_dog.The_quick_brown_fox_jumps_over_the_lazy_dog.The_quick_brown_fox_jumps_over_the_lazy_dog.
----
EOT
# Check ASCII output.
rt = newRichText(inp)
rt.lineWidth = 60
out = rt.to_s + "\n"
ref = <<EOT
The_quick_brown_fox_jumps_over_the_lazy_dog.The_quick_brown_fox_jumps_over_the_lazy_dog.The_quick_brown_fox_jumps_over_the_lazy_dog.
------------------------------------------------------------
EOT
match(ref, out)
end
def test_bulletWrapping
inp = <<EOT
* The quick brown fox jumps over the lazy dog.
* The quick brown fox jumps over the lazy dog.
** The quick brown fox jumps over the lazy dog.
*** The quick brown fox jumps over the lazy dog.
----
EOT
# Check ASCII output.
rt = newRichText(inp)
rt.lineWidth = 22
out = rt.to_s + "\n"
ref = <<EOT
* The quick brown fox
jumps over the lazy
dog.
* The quick brown fox
jumps over the lazy
dog.
* The quick brown
fox jumps over the
lazy dog.
* The quick brown
fox jumps over
the lazy dog.
----------------------
EOT
match(ref, out)
end
def test_fontCol
inp = 'A <fcol:blue>blue</fcol> word.'
tagged = "<div>[A] <fcol:blue>[blue]</fcol> [word.]</div>\n"
str = "A blue word.\n"
html = "<div>A <span style=\"color:blue\">blue</span> word.</div>\n"
assert_outputs(inp, tagged, str, html)
end
def newRichText(text)
mh = TaskJuggler::MessageHandlerInstance.instance
mh.outputLevel = :none
rText = TaskJuggler::RichText.new(text, [ RTFDummy.new ])
assert(rti = rText.generateIntermediateFormat, mh.to_s)
rti.linkTarget = '_blank'
rti
end
def assert_outputs(inp, tagged, str, html, width = 80)
# Check tagged output.
assert_tagged(inp, tagged)
# Check ASCII output.
assert_str(inp, str, width)
# Check HTML output.
assert_html(inp, html, width)
end
def assert_tagged(inp, ref)
out = newRichText(inp).to_tagged + "\n"
match(ref, out)
end
def assert_str(inp, ref, width)
rt = newRichText(inp)
rt.lineWidth = width
out = rt.to_s + "\n"
match(ref, out)
end
def assert_html(inp, ref, width)
rt = newRichText(inp)
rt.lineWidth = width
out = rt.to_html.to_s + "\n"
match(ref, out)
end
def match(ref, out)
if ref != out
common = ''
refDiff = ''
outDiff = ''
diffI = nil
len = ref.length < out.length ? ref.length : out.length
len.times do |i|
if ref[i] == out[i]
common << ref[i]
else
diffI = i
break
end
end
refDiff = ref[diffI,20] + '...' if diffI && ref.length > diffI
outDiff = out[diffI,20] + '...' if diffI && out.length > diffI
end
assert_equal(ref, out, "=== Maching part: #{'=' * 40}\n" +
"#{common}\n" +
"=== ref diff #{'=' * 44}\n" +
"#{refDiff}\n" +
"=== out diff #{'=' * 44}\n" +
"#{outDiff}\n")
end
end
|