#!/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
# by Chris Schlaeger
#
# 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 'RichText'
require 'RichTextFunctionHandler'
require 'MessageHandler'
class RTFDummy < TaskJuggler::RichTextFunctionHandler
def initialize()
super(nil, '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 = "\n"
str = "\n"
html = "\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 = "
\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'
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'
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
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'
----
[Line] [above] [and] [below]
----
1 [A] [heading]
----
----
----
[Another] [bit] [of] [text.]
----
EOT
str = <<'EOT'
------------------------------------------------------------
Line above and below
------------------------------------------------------------
1) A heading
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Another bit of text.
------------------------------------------------------------
EOT
html = <<'EOT'
Line above and below
1 A heading
Another bit of text.
EOT
assert_outputs(inp, tagged, str, html, 60)
end
def test_italic
inp = "This is a text with ''italic words '' in it."
tagged = <<'EOT'
EOT
str = <<'EOT'
This is a text with monospaced words in it.
EOT
html = <<'EOT'
This is a text with monospaced words in it.
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'
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'
This is a text with some bold words, some italic words and some bold and italic words in it.
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'
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'
EOT
str = <<'EOT'
This is an . For more info see this image.
EOT
html = <<'EOT'
This is an . For more info see .
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'
EOT
assert_outputs(inp, tagged, str, html)
end
def test_hrefWithWrappedLines
inp = <<'EOT'
A [http://www.taskjuggler.org
multi line] reference.
EOT
tagged = <<'EOT'
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'
[=] [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
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'
= 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
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'
* [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
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'
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
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'
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
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'
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
assert_outputs(inp, tagged, str, html)
end
def test_pre
inp = <<'EOT'
#include
main() {
printf("Hello, world!\n")
}
Some normal text.
* A
bullet
item
Some code
More text.
EOT
tagged = <<'EOT'
#include
main() {
printf("Hello, world!\n")
}
[Some] [normal] [text.]
* [A] [bullet] [item]
Some code
[More] [text.]
EOT
str = <<'EOT'
#include
main() {
printf("Hello, world!\n")
}
Some normal text.
* A bullet item
Some code
More text.
EOT
html = <<'EOT'
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'
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'
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
A number item
A bullet
Number 0.1, I guess
2 Section 2
Starts with bullets
...
Some more text. And we're done.
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 ''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'
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'
1 This the first section
1.1 This is the section 1.1
Not sure ''what'' to put here. Maybe just some silly text.