require 'trac-wiki' class Bacon::Context def tc(html, wiki, options = {}) TracWiki.render(wiki, options).should.equal html end end describe TracWiki::Parser do it 'should not parse linkd' do tc "
[[ahoj]]
\n", "[[ahoj]]", :no_link => true tc "[[ahoj|bhoj]]
\n", "[[ahoj|bhoj]]", :no_link => true tc "This is bold
\n", "This **is** bold" tc "This is bold and boldish
\n", "This **is** bold and **bold**ish" # Bold can be used inside list items tc "This is bold |
A bold link: http://example.org/ nice!
\n", "A bold link: **http://example.org/ nice! **") # Bold will end at the end of paragraph tc "This is bold
\n", "This **is bold" # Bold will end at the end of list items tc("Item bold | Another bold |
This is
\nbold maybe
\n", "This **is\n\nbold** maybe") # Bold should be able to cross lines tc "This is bold
\n", "This **is\nbold**" end it 'should be toc' do tc "{{toc}}
\n", "{{toc}}" tc "{{toc}}
\n{{toc}}
\nThis is bolditallic.
\n", "This is '''''bolditallic'''''." tc "This is bolditallic .
\n", "This is ''' ''bolditallic'' '''." tc "This is bolditallic .
\n", "This is '' '''bolditallic''' ''." tc "This is bold.
\n", "This is '''bold'''." #fuj tc 'This is bolditallic.
\n', "This is **''bolditallic**''." end it 'should parse monospace' do tc "This is monospace.
\n", "This is {{{monospace}}}." tc "This is mon**o**space.
\n", "This is {{{mon**o**space}}}." tc "This is mon<o>space.
\n", "This is {{{monThis is mon''o''space.
\n", "This is {{{mon''o''space}}}." tc "This is mon''o''space.
\n", "This is `mon''o''space`." tc "This is mon{{o}}space.
\n", "This is {{{mon{{o}}space}}}." tc "This is mon``o''space.
\n", "This is {{{mon``o''space}}}." tc "This is mon{{o}}space.
\n", "This is `mon{{o}}space`." end it 'should parse italic' do # Italic can be used inside paragraphs tc("This is italic
\n", "This ''is'' italic") tc("This is italic and italicish
\n", "This ''is'' italic and ''italic''ish") # Italic can be used inside list items tc "This is italic |
A italic link: http://example.org/ nice!
\n", "A italic link: ''http://example.org/ nice! ''") # Italic will end at the end of paragraph tc "This is italic
\n", "This ''is italic" # Italic will end at the end of list items tc("Item italic | Another italic |
This is
\nitalic maybe
\n", "This ''is\n\nitalic'' maybe") # Italic should be able to cross lines tc "This is italic
\n", "This ''is\nitalic''" end it 'should parse bold italics' do # By example tc "bold italics
\n", "**''bold italics''**" # By example tc "bold italics
\n", "''**bold italics**''" # By example tc "This is also good.
\n", "''This is **also** good.''" end it 'should parse math' do tc "\\( the \\)
\n", '$the$', math: true tc "test \\( the \\) west
\n", 'test $the$ west', math: true tc "test \\( e^{i\\pi} \\) test
\n", 'test $e^{i\pi}$ test', math: true tc "test $ e{i\\pi} test
\n", 'test $ e^{i\pi} test', math: true tc "$the$
\n", '$the$', math: false tc "ahoj
\n$$e^{i\\pi}$$\nnazdar
\n", "ahoj\n$$e^{i\\pi}$$\nnazdar", math: true tc "ahoj $$e{i\\pi}$$ nazdar
\n", "ahoj\n$$e^{i\\pi}$$\nnazdar", math: false tc "$$\\\\$$\n", "$$\\\\$$", math: true tc "$$\n^test\n$$\n", "$$\n^test\n$$", math: true tc "$abc$
\n", "!$a^b^c$", math: true tc "$abc$
\n", "!$a**b**c$", math: true tc "!$a$
\n", "!!!$a$", math: true end it 'should parse headings' do # Only three differed sized levels of heading are required. tc "== Heading 2 == foo
\n", " == Heading 2 == foo" tc "foo = Heading 1 =
\n", "foo = Heading 1 =" end it 'should parse links' do # Links tc "\n", "[[link]]" # Links can appear in paragraphs (i.e. inline item) tc "Hello, world
\n", "Hello, [[world]]" # Named links tc "\n", "[[MyBigPage|Go to my page]]" # URLs tc "\n", "[[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}
\n", "http://www.example.org/#{punct}" end # Nameds URLs (by example) tc("\n", "[[http://www.example.org/|Visit the Example website]]") # WRNING: Parsing markup within a link is optional tc "\n", "[[Weird Stuff|**Weird** ''Stuff'']]" #tc("\n", "[[http://example.org/|{{image.jpg}}]]") # Inside bold tc "\n", "**[[link]]**" # Whitespace inside [[ ]] should be ignored tc("\n", "[[ link ]]") tc("\n", "[[ link me ]]") tc("\n", "[[ http://dot.com/ \t| \t dot.com ]]") tc("\n", "[[ http://dot.com/ | dot.com ]]") end it 'should parse freestanding urls' do # Free-standing URL's should be turned into links tc "\n", "http://www.example.org/" # URL ending in . tc "Text http://example.org. other text
\n", "Text http://example.org. other text" # URL ending in ), tc "Text (http://example.org), other text
\n", "Text (http://example.org), other text" # URL ending in ). tc "Text (http://example.org). other text
\n", "Text (http://example.org). other text" # URL ending in ). tc "Text (http://example.org).
\n", "Text (http://example.org)." # URL ending in ) tc "Text (http://example.org)
\n", "Text (http://example.org)" end it 'should parse paragraphs' do # One or more blank lines end paragraphs. tc "This is my text.
\nThis is more text.
\n", "This is\nmy text.\n\nThis is\nmore text." tc "This is my text.
\nThis is more text.
\n", "This is\nmy text.\n\n\nThis is\nmore text." tc "This is my text.
\nThis is more text.
\n", "This is\nmy text.\n\n\n\nThis is\nmore text." # A list end paragraphs too. tc "Hello
\nHello
\nCell |
Hello
\nnowiki", "Hello\n{{{\nnowiki\n}}}\n" # WARNING: A heading ends a paragraph (not specced) tc "
Hello
\nThis 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\n", "> Monty Python\n" tc "
Monty Python q2\n", "> Monty Python\n> q2\n" tc "
Monty Python q2\n", "> Monty Python\n>q2\n" tc "
Monty Python q2\n", "> Monty Python\n>**q2**\n" tc "
Monty Python\n", "> Monty Python\n> > q2\n" tc "q2
Monty Python\n", "> Monty Python\n> > q2\n>>q3\n" tc "q2 q3
Monty Python\n", ">Monty Python\n> > ''q2''\n>q1" tc "q2q1
Monty Python rules\n", " Monty Python\n rules\n" end it 'should parse definition list' do # FIXME: trailing space tc "
Monty::Python::definition
\n", "Monty::Python::definition\n" tc "bla Monty::Python bla
\n", "bla Monty::Python bla\n" tc "bla Monty::Python
\n", "bla Monty::Python\n" tc "Monty::Python bla
\n", "Monty::Python bla\n" tc "::Python bla
\n", "::Python bla\n" tc ":: Python bla
\n", ":: Python bla\n" end it 'should parse unordered_lists' do # List items begin with a * at the beginning of a line. # An item ends at the next * tc "Par
\n", "* 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
\n", "* 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
\n", "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.
\n", "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?
\n", "How about ''a link, like http://example.org, in italic'' text?") tc("How about a link, like http://example.org, in italic text?
\n", "How about ''a link, like [http://example.org], in italic'' text?") # Another test tc("Formatted fruits, for example:apples, oranges, pears ...
\n", "Formatted fruits, for example:''apples'', oranges, **pears** ...") end it 'should parse ambiguious bold and lists' do tc "bold text
\n", "** bold text **" tc "bold text\n", " ** bold text **" end it 'should parse nowiki' do # ... works as block tc "
Hello", "{{{\nHello\n}}}\n" tc "
{{{-}}}
\n", "`{{{-}}}`\n" # ... works inline tc "Hello world.
\n", "Hello {{{world}}}." tc "Hello world.
\n", "{{{Hello}}} {{{world}}}." # No wiki markup is interpreted inbetween tc "**Hello**", "{{{\n**Hello**\n}}}\n" # Leading whitespaces are not permitted # tc("
{{{ Hello }}}
\n", " {{{\nHello\n}}}") tc("{{{ Hello
}}}\n", "{{{\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}
\n", "this is {{{nowiki}}}}") tc("this is nowiki}}
\n", "this is {{{nowiki}}}}}") tc("this is nowiki}}}
\n", "this is {{{nowiki}}}}}}") tc("this is nowiki}}}}
\n", "this is {{{nowiki}}}}}}}") end it 'should escape html' do # Special HTML chars should be escaped tc("<b>not bold</b>
\n", "not bold") # Image tags should be escape tc("\n", "[[Image(image.jpg)]]") tc("\n", "[[Image(image.jpg)]]", :no_link=>true) tc("\n", "[[Image(image.jpg,alt=a\"tag\")]]") tc("\n", "[[Image(image.jpg,alt=a\"tag\")]]", :no_link=>true) # Malicious links should not be converted. tc("\n", "[[javascript:alert(\"Boo!\")|Click]]") end it 'should support character escape' do tc "** Not Bold **
\n", "!** Not Bold !**" tc "// Not Italic //
\n", "!// Not Italic !//" tc "* Not Bullet
\n", "!* Not Bullet" # Following char is not a blank (space or line feed) tc "Hello ~ world
\n", "Hello ~ world\n" tc "Hello ! world
\n", "Hello ! world\n" tc "Hello ! world
\n", "Hello ! world\n" tc "Hello ! world
\n", "Hello !\nworld\n" # Not escaping inside URLs tc "\n", "http://example.org/~user/" tc "\n", "[http://example.org/~user/]" tc "\n", "[http://example.org/~user/]", :no_link=>true tc "\n", "[[http://example.org/~user/]]", :no_link=>true tc "\n", "[[http://example.org/~user/]]" # Escaping links tc "http://www.example.org/
\n", "!http://www.example.org/" tc "[http://www.example.org/]
\n", "![!http://www.example.org/]" tc "\n", "![http://www.example.org/]" end it 'should parse horizontal rule' do # Four hyphens make a horizontal rule tc "foo ----
\n", "foo ----\n" tc "---- foo
\n", "---- foo\n" # [...] no whitespace is allowed between them tc "-- --
\n", "-- -- " tc "-- --
\n", "--\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 |
c1 | Link text |
table |
table |
table |
par
\n", "||table||\npar\n") tc("table |
par
\n", "||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
\n", "=heading=\npar\n") tc("par
\n", "=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
\npar
\npar par
\n", "par\npar\n") tc("par
\npar
\n", "par\n\npar\n") # unordered tc("par
\npar
\npar
\npar
\npar
\npar
\npar
\nnowiki", "par\n{{{\nnowiki\n}}}\n") tc("
par
\nnowiki", "par\n\n{{{\nnowiki\n}}}\n") # table tc("
par
\ntable |
par
\ntable |
par
\n", "* 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
\n", "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
\n", "----\npar\n") tc("par
\n", "----\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
\n", "{{{\nnowiki\n}}}\npar") tc("nowiki
par
\n", "{{{\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
\ntable |
end
\n", "**bold and\n||table||\nend**") end it 'should support font styles below' do tc("This is underlined
\n", "This is __underlined__") tc("This is deleted
This is super
\n", "This is ^super^") tc("This is sub
\n", "This is ,,sub,,") end it 'should not support signs' do TracWiki.render("(R)").should.not.equal "®
\n" TracWiki.render("(r)").should.not.equal "®
\n" TracWiki.render("(C)").should.not.equal "©
\n" TracWiki.render("(c)").should.not.equal "©
\n" end it 'should support no_escape' do tc("\n", "[[a/b/c]]") tc("\n", "[a/b/c]") tc("\n", "[[a/b/c]]", :no_escape => true) end it 'should support merge' do tc "bhoj
\nahoj
\n", "bhoj\n>>>>>>> your\nahoj", :merge => true tc "\nahoj
\n", "=======\nahoj\n", :merge => true tc "ahoj
\n", "=======\nahoj\n", :merge => false end end # vim: tw=0