#!/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 = "
[foo]
\n" str = "foo\n" html= "
foo
\n" assert_outputs(inp, tagged, str, html) end def test_two_words inp = "foo bar" tagged = "
[foo] [bar]
\n" str = "foo bar\n" html = "
foo bar
\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'

[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 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'
[This] [is] [a] [text] [with] [italic] [words] [in] [it.]
EOT str = <<'EOT' This is a text with italic words in it. EOT html = <<'EOT'
This is a text with italic words in it.
EOT assert_outputs(inp, tagged, str, html) end def test_bold inp = "This is a text with ''' bold words''' in it." tagged = <<'EOT'
[This] [is] [a] [text] [with] [bold] [words] [in] [it.]
EOT str = <<'EOT' This is a text with bold words in it. EOT html = <<'EOT'
This is a text with bold words in it.
EOT assert_outputs(inp, tagged, str, html) end def test_code inp = "This is a text with ''''monospaced words'''' in it." tagged = <<'EOT'
[This] [is] [a] [text] [with] [monospaced] [words] [in] [it.]
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'
[This] [is] [a] [text] [with] [some] [bold] [words][,] [some] [italic] [words] [and] [some] [bold] [and] [italic] [words] [in] [it.]
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'
[This] [is] [a] [reference] [item][.] [For] [more] [info] [see] [the user manual][.]
EOT str = <<'EOT' This is a reference item. For more info see the user manual. EOT html = <<'EOT'
This is a reference item. For more info see the user manual.
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'
[This] [is] [an] [.] [For] [more] [info] [see] [.]
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'
[This] [is] [a] [reference] [http://www.taskjuggler.org][.] [For] [more] [info] [see] [the] [TaskJuggler] [site][.]
EOT str = <<'EOT' This is a reference http://www.taskjuggler.org. For more info see the TaskJuggler site. EOT html = <<'EOT'
This is a reference http://www.taskjuggler.org. For more info see the TaskJuggler site.
EOT assert_outputs(inp, tagged, str, html) end def test_hrefWithWrappedLines inp = <<'EOT' A [http://www.taskjuggler.org multi line] reference. EOT tagged = <<'EOT'
[A] [multi] [line] [reference.]
EOT str = <<'EOT' A multi line reference. EOT html = <<'EOT'
A multi line reference.
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'
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'
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. 1 [This] [is] [item] [1]
  2. 2 [This] [is] [item] [2]
  3. 3 [This] [is] [item] [3]

[Normal] [text.]

  1. 1 [This] [is] [item] [1]
    1. 1.1 [This] [is] [item] [1.1]
    2. 1.2 [This] [is] [item] [1.2]
    3. 1.3 [This] [is] [item] [1.3]
  2. 2 [This] [is] [item] [2]
    1. 2.1 [This] [is] [item] [2.1]
    2. 2.2 [This] [is] [item] [2.2]
      1. 2.2.1 [This] [is] [item] [2.2.1]
      2. 2.2.2 [This] [is] [item] [2.2.2]
        1. 2.2.2.1 [This] [is] [item] [2.2.2.1]
  3. 3 [This] [is] [item] [3]
    1. 3.1 [This] [is] [item] [3.1]
      1. 3.1.1 [This] [is] [item] [3.1.1]
  4. 4 [This] [is] [item] [4]
      1. 4.0.1 [This] [is] [item] [4.0.1]

[Normal] [text.]

  1. 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'
  1. This is item 1
  2. This is item 2
  3. This is item 3

Normal text.

  1. This is item 1
    1. This is item 1.1
    2. This is item 1.2
    3. This is item 1.3
  2. This is item 2
    1. This is item 2.1
    2. This is item 2.2
      1. This is item 2.2.1
      2. This is item 2.2.2
        1. This is item 2.2.2.1
  3. This is item 3
    1. This is item 3.1
      1. This is item 3.1.1
  4. This is item 4
      1. This is item 4.0.1

Normal text.

  1. 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'
#include <stdin.h>
main() {
  printf("Hello, world!\n")
}

Some normal text.

  • A bullet item
Some code

More text.

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'

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. 1 [A] [number] [item]
  • * [A] [bullet]
    1. 0.1 [Number] [0.1,] [I] [guess]

2 [Section] [2]

  • * [Starts] [with] [bullets]
  • * [...]

[Some] [more] [text.] [And] [we]['re] [done.]

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
  1. A number item
  • A bullet
    1. 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'

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. 1 [A] [number] [item]
  • * [A] [bullet]

[##] [Number] [0.1,] [I] [guess]

[==] [Section] [2] [==]

  • * [Starts] [with] [bullets]
  • * [...]

[Some] [more] [text.] [And] [we]['re] [done.]

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.

  • 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 assert_outputs(inp, tagged, str, html) end def test_hline_and_link inp = <
----

[bar]

EOT str = <bar

\n\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'

0.1 [Header]

[some] [text]

EOT str = <

some text

EOT assert_outputs(inp, tagged, str, html, 60) end def test_stringLineWrapping inp = < 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