require 'trac_wiki' class Bacon::Context def tc(html, wiki, options = {}) TracWiki.render(wiki, options).should.equal html end def tce(html, wiki) tc(html, wiki, :extensions => true) end end describe TracWiki::Parser do it 'should parse bold' do # Bold can be used inside paragraphs tc "
This is bold
", "This **is** bold" tc "This is bold and boldish
", "This **is** bold and **bold**ish" # Bold can be used inside list items tc "This is bold |
A bold link: http://example.org/ nice!
", "A bold link: **http://example.org/ nice! **") # Bold will end at the end of paragraph tc "This is bold
", "This **is bold" # Bold will end at the end of list items tc("Item bold | Another bold |
This is
bold maybe
", "This **is\n\nbold** maybe") # Bold should be able to cross lines tc "This is bold
", "This **is\nbold**" end it 'should parse bolditalic' do tc 'This is bolditallic.
', "This is '''''bolditallic'''''." tc 'This is bolditallic .
', "This is ''' ''bolditallic'' '''." tc 'This is bolditallic .
', "This is '' '''bolditallic''' ''." tc 'This is bold.
', "This is '''bold'''." #fuj tc 'This is bolditallic.
', "This is **''bolditallic**''." end it 'should parse monospace' do tc "This is monospace.
", "This is {{{monospace}}}." tc "This is mon**o**space.
", "This is {{{mon**o**space}}}." tc "This is mon<o>space.
", "This is {{{monThis is mon''o''space.
", "This is {{{mon''o''space}}}." tc "This is mon''o''space.
", "This is `mon''o''space`." tc "This is mon{{o}}space.
", "This is {{{mon{{o}}space}}}." tc "This is mon``o''space.
", "This is {{{mon``o''space}}}." tc "This is mon{{o}}space.
", "This is `mon{{o}}space`." end it 'should parse italic' do # Italic can be used inside paragraphs tc("This is italic
", "This ''is'' italic") tc("This is italic and italicish
", "This ''is'' italic and ''italic''ish") # Italic can be used inside list items tc "This is italic |
A italic link: http://example.org/ nice!
", "A italic link: ''http://example.org/ nice! ''") # Italic will end at the end of paragraph tc "This is italic
", "This ''is italic" # Italic will end at the end of list items tc("Item italic | Another italic |
This is
italic maybe
", "This ''is\n\nitalic'' maybe") # Italic should be able to cross lines tc "This is italic
", "This ''is\nitalic''" end it 'should parse bold italics' do # By example tc "bold italics
", "**''bold italics''**" # By example tc "bold italics
", "''**bold italics**''" # By example tc "This is also good.
", "''This is **also** good.''" end it 'should parse headings' do # Only three differed sized levels of heading are required. tc "== Heading 2 == foo
", " == Heading 2 == foo" tc "foo = Heading 1 =
", "foo = Heading 1 =" end it 'should parse links' do # Links tc "", "[[link]]" # Links can appear in paragraphs (i.e. inline item) tc "Hello, world
", "Hello, [[world]]" # Named links tc "", "[[MyBigPage|Go to my page]]" # URLs tc "", "[[http://www.example.org/]]" # Single punctuation characters at the end of URLs # should not be considered a part of the URL. [',','.','?','!',':',';','\'','"'].each do |punct| esc_punct = CGI::escapeHTML(punct) tc "http://www.example.org/#{esc_punct}
", "http://www.example.org/#{punct}" end # Nameds URLs (by example) tc("", "[[http://www.example.org/|Visit the Example website]]") # WRNING: Parsing markup within a link is optional tc "", "[[Weird Stuff|**Weird** ''Stuff'']]" #tc("", "[[http://example.org/|{{image.jpg}}]]") # Inside bold tc "", "**[[link]]**" # Whitespace inside [[ ]] should be ignored tc("", "[[ link ]]") tc("", "[[ link me ]]") tc("", "[[ http://dot.com/ \t| \t dot.com ]]") tc("", "[[ http://dot.com/ | dot.com ]]") end it 'should parse freestanding urls' do # Free-standing URL's should be turned into links tc "", "http://www.example.org/" # URL ending in . tc "Text http://example.org. other text
", "Text http://example.org. other text" # URL ending in ), tc "Text (http://example.org), other text
", "Text (http://example.org), other text" # URL ending in ). tc "Text (http://example.org). other text
", "Text (http://example.org). other text" # URL ending in ). tc "Text (http://example.org).
", "Text (http://example.org)." # URL ending in ) tc "Text (http://example.org)
", "Text (http://example.org)" end it 'should parse paragraphs' do # One or more blank lines end paragraphs. tc "This is my text.
This is more text.
", "This is\nmy text.\n\nThis is\nmore text." tc "This is my text.
This is more text.
", "This is\nmy text.\n\n\nThis is\nmore text." tc "This is my text.
This is more text.
", "This is\nmy text.\n\n\n\nThis is\nmore text." # A list end paragraphs too. tc "Hello
Hello
Cell |
Hello
nowiki", "Hello\n{{{\nnowiki\n}}}\n" # WARNING: A heading ends a paragraph (not specced) tc "
Hello
This is the first line,
and this is the second.
This is the first line,
and this is the second.
This is the first line,
and this is the second.
Monty Python", "> Monty Python\n" tc "
Monty Python q2", "> Monty Python\n> q2\n" tc "
Monty Python q2", "> Monty Python\n>q2\n" tc "
Monty Python q2", "> Monty Python\n>**q2**\n" tc "
Monty Python", "> Monty Python\n> > q2\n" tc "q2
Monty Python", "> Monty Python\n> > q2\n>>q3\n" tc "q2 q3
Monty Python", ">Monty Python\n> > ''q2''\n>q1" tc "q2q1
Monty Python rules", " Monty Python\n rules\n" end it 'should parse definition list' do # FIXME: trailing space tc "
Par
", "* Item\n\nPar\n") # An item ends at a heading tc("Cell |
Code", "* Item\n{{{\nCode\n}}}\n") # An item can span multiple lines tc("
Not bold
", "* Hello,\nWorld!\n\n**Not bold\n") end it 'should parse ordered lists' do # List items begin with a * at the beginning of a line. # An item ends at the next * tc "Par
", "1. Item\n\nPar\n") # An item ends at a heading tc("Cell |
Code", "1. Item\n{{{\nCode\n}}}\n") # An item can span multiple lines tc("
This is what can go wrong:this should be an italic text.
", "This is what can go wrong:''this should be an italic text''.") # A link inside italic text tc("How about a link, like http://example.org, in italic text?
", "How about ''a link, like http://example.org, in italic'' text?") # Another test tc("Formatted fruits, for example:apples, oranges, pears ...
", "Formatted fruits, for example:''apples'', oranges, **pears** ...") end it 'should parse ambiguious bold and lists' do tc "bold text
", "** bold text **" tc "bold text", " ** bold text **" end it 'should parse nowiki' do # ... works as block tc "
Hello", "{{{\nHello\n}}}\n" tc "
{{{-}}}
", "`{{{-}}}`\n" # ... works inline tc "Hello world.
", "Hello {{{world}}}." tc "Hello world.
", "{{{Hello}}} {{{world}}}." # No wiki markup is interpreted inbetween tc "**Hello**", "{{{\n**Hello**\n}}}\n" # Leading whitespaces are not permitted # tc("
{{{ Hello }}}
", " {{{\nHello\n}}}") tc("{{{ Hello
}}}", "{{{\nHello\n }}}") # Assumed: Should preserve whitespace tc("
\t Hello, \t \n \t World \t", "{{{\n \t Hello, \t \n \t World \t \n}}}\n") # In preformatted blocks ... one leading space is removed tc("
nowikiblock\n}}}", "{{{\nnowikiblock\n }}}\n}}}\n") # In inline nowiki, any trailing closing brace is included in the span tc("
this is nowiki}
", "this is {{{nowiki}}}}") tc("this is nowiki}}
", "this is {{{nowiki}}}}}") tc("this is nowiki}}}
", "this is {{{nowiki}}}}}}") tc("this is nowiki}}}}
", "this is {{{nowiki}}}}}}}") end it 'should escape html' do # Special HTML chars should be escaped tc("<b>not bold</b>
", "not bold") # Image tags should be escape tc("", "[[Image(image.jpg)]]") tc("", "[[Image(image.jpg|\"tag\")]]") # Malicious links should not be converted. tc("", "[[javascript:alert(\"Boo!\")|Click]]") end it 'should support character escape' do tc "** Not Bold **
", "!** Not Bold !**" tc "// Not Italic //
", "!// Not Italic !//" tc "* Not Bullet
", "!* Not Bullet" # Following char is not a blank (space or line feed) tc "Hello ~ world
", "Hello ~ world\n" tc "Hello ! world
", "Hello ! world\n" tc "Hello ! world
", "Hello ! world\n" tc "Hello ! world
", "Hello !\nworld\n" # Not escaping inside URLs tc "", "http://example.org/~user/" # Escaping links tc "http://www.example.org/
", "~http://www.example.org/" end it 'should parse horizontal rule' do # Four hyphens make a horizontal rule tc "foo ----
", "foo ----\n" tc "---- foo
", "---- foo\n" # [...] no whitespace is allowed between them tc "-- --
", "-- -- " tc "-- --
", "--\t-- " end it 'should parse table' do tc "Hello | World! |
Hello | World! |
He | llo | World! |
Hello | World! |
Hello | kuk | World! |
1 | 2 | 3 |
1-2 | 3 | |
1 | 2-3 | |
1-2-3 |
table | center |
table | right |
table | center | right |
Hello, World! |
Hello, Right World! |
Hello, Right World! |
---|
Hello, Centered World! |
Hello, Centered World! |
---|
c1 | c2 | c3 |
c11 | c12 |
c21 | c22 |
c1 | c2 | c3 |
c1 | c2 |
c1|c2 | c3 |
c1 | c2| |
c1 | c2| |
c1 | c2| |
Header |
---|
c1 | Link text |
table |
table |
table |
par
", "||table||\npar\n") tc("table |
par
", "||table||\n\npar\n") # table followed by unordered list tc("table |
table |
table |
table |
table |
table |
table |
pre", "||table||\n{{{\npre\n}}}\n") tc("
table |
pre", "||table||\n\n{{{\npre\n}}}\n") # table followed by table tc("
table |
table |
table |
table |
par
", "=heading=\npar\n") tc("par
", "=heading=\n\npar\n") # unordered list tc("nowiki", "=heading=\n{{{\nnowiki\n}}}\n") tc("
nowiki", "=heading=\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
par
par
par par
", "par\npar\n") tc("par
par
", "par\n\npar\n") # unordered tc("par
par
par
par
par
par
par
nowiki", "par\n{{{\nnowiki\n}}}\n") tc("
par
nowiki", "par\n\n{{{\nnowiki\n}}}\n") # table tc("
par
table |
par
table |
par
", "* item\n\npar\n") # unordered tc("nowiki", "* item\n{{{\nnowiki\n}}}\n") tc("
nowiki", "* item\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
par
", "1. item\n\npar\n") # unordered tc("nowiki", "1. item\n{{{\nnowiki\n}}}\n") tc("
nowiki", "1. item\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
par
", "----\npar\n") tc("par
", "----\n\npar\n") # unordered tc("nowiki", "----\n{{{\nnowiki\n}}}\n") tc("
nowiki", "----\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
nowiki
nowiki
nowiki
par
", "{{{\nnowiki\n}}}\npar") tc("nowiki
par
", "{{{\nnowiki\n}}}\n\npar") # unordered tc("nowiki
nowiki
nowiki
nowiki
nowiki
nowiki
nowiki
nowiki", "{{{\nnowiki\n}}}\n{{{\nnowiki\n}}}\n") tc("
nowiki
nowiki", "{{{\nnowiki\n}}}\n\n{{{\nnowiki\n}}}\n") # table tc("
nowiki
table |
nowiki
table |
bold and
table |
end
", "**bold and\n||table||\nend**") end it 'should support extensions' do tce("This is underlined
", "This is __underlined__") tce("This is deleted
This is super
", "This is ^super^") tce("This is sub
", "This is ,,sub,,") tce("®
", "(R)") tce("®
", "(r)") tce("©
", "(C)") tce("©
", "(c)") end it 'should support no_escape' do tc("", "[[a/b/c]]") tc("", "[[a/b/c]]", :no_escape => true) end end # vim: tw=0