test/wiki_cloth_test.rb in wikicloth-0.8.0 vs test/wiki_cloth_test.rb in wikicloth-0.8.1

- old
+ new

@@ -4,10 +4,14 @@ class WikiParser < WikiCloth::Parser url_for do |page| page end + image_url_for do |url| + File.join("/images/", url) + end + template do |template| case template when "noinclude" "<noinclude>hello world</noinclude><includeonly>testing</includeonly>" when "test" @@ -33,10 +37,50 @@ end end class WikiClothTest < ActiveSupport::TestCase + test "a url should be automaticly linked" do + wiki = WikiCloth::Parser.new(:data => "\n\n\nhttp://www.google.com/") + data = wiki.to_html + assert data.include?('<a href="http://www.google.com/">') + wiki = WikiCloth::Parser.new(:data => "hello http://www.google.com/ world") + data = wiki.to_html + assert data.include?('<a href="http://www.google.com/">') + wiki = WikiCloth::Parser.new(:data => "http://www.google.com/") + data = wiki.to_html + assert data.include?('<a href="http://www.google.com/">') + wiki = WikiCloth::Parser.new(:data => "[https://github.com/repo/README.md README]") + data = wiki.to_html + assert data.include?('https://github.com/repo/README.md') + assert data =~ /\>\s*README\s*\</ + end + + test "image url override" do + wiki = WikiCloth::Parser.new(:data => "[[Image:test.jpg]]") + data = wiki.to_html + assert !data.include?("/images/test.jpg") + assert data.include?("\"test.jpg\"") + + wiki = WikiParser.new(:data => "[[Image:test.jpg]]") + data = wiki.to_html + assert data.include?("/images/test.jpg") + end + + test "wiki table attributes without quotes" do + wiki = WikiParser.new(:data => "{| width=\"95%\" +!colspan=2 style=\"background-color:#ffebac;\"|Heading +|- +|hello||world +|}") + data = wiki.to_html + assert data.include?("<table width=\"95%\">") + assert data.include?("colspan=\"2\"") + assert data.include?("hello") + assert data.include?("world") + end + test "nested bold/italic markup" do wiki = WikiParser.new(:data => "''Mars goes around the Sun once in a Martian '''year''', or 1.88 Earth '''years'''.''") data = wiki.to_html assert data.include?("<i>Mars goes around the Sun once in a Martian <b>year</b>, or 1.88 Earth <b>years</b>.</i>") end @@ -394,11 +438,11 @@ end test "empty item in toc" do wiki = WikiCloth::WikiCloth.new({:data => "__TOC__\n=A="}) data = wiki.render - assert data.include?("<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">A</a></li></ul></td></tr></table>") + assert data.include?("<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div id=\"toctitle\"><h2>Table of Contents</h2></div><ul></li><li><a href=\"#A\">A</a></li></ul></td></tr></table>") end test "pre at beginning" do wiki = WikiCloth::WikiCloth.new({:data => " A"}) data = wiki.render @@ -406,14 +450,14 @@ end test "toc declared as list" do wiki = WikiCloth::WikiCloth.new({:data => "__TOC__\n=A=\n==B==\n===C==="}) data = wiki.render - assert data.include?("<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">A</a><ul><li><a href=\"#B\">B</a><ul><li><a href=\"#C\">C</a></li></ul></ul></ul></td></tr></table>") + assert data.include?("<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div id=\"toctitle\"><h2>Table of Contents</h2></div><ul></li><li><a href=\"#A\">A</a><ul><li><a href=\"#B\">B</a><ul><li><a href=\"#C\">C</a></li></ul></ul></ul></td></tr></table>") end test "toc numbered" do wiki = WikiCloth::WikiCloth.new({:data => "=A=\n=B=\n==C==\n==D==\n===E===\n===F===\n====G====\n====H====\n==I==\n=J=\n=K=\n===L===\n===M===\n====N====\n====O===="}) data = wiki.render(:noedit => true, :toc_numbered => true) - assert data.include?("<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">1 A</a></li><li><a href=\"#B\">2 B</a><ul><li><a href=\"#C\">2.1 C</a></li><li><a href=\"#D\">2.2 D</a><ul><li><a href=\"#E\">2.2.1 E</a></li><li><a href=\"#F\">2.2.2 F</a><ul><li><a href=\"#G\">2.2.2.1 G</a></li><li><a href=\"#H\">2.2.2.2 H</a></li></ul></ul><li><a href=\"#I\">2.3 I</a></li></ul><li><a href=\"#J\">3 J</a></li><li><a href=\"#K\">4 K</a><ul><ul><li><a href=\"#L\">4.1 L</a></li><li><a href=\"#M\">4.2 M</a><ul><li><a href=\"#N\">4.2.1 N</a></li><li><a href=\"#O\">4.2.2 O</a></li></ul></ul></ul></ul></td></tr></table>") + assert data.include?("<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div id=\"toctitle\"><h2>Table of Contents</h2></div><ul></li><li><a href=\"#A\">1 A</a></li><li><a href=\"#B\">2 B</a><ul><li><a href=\"#C\">2.1 C</a></li><li><a href=\"#D\">2.2 D</a><ul><li><a href=\"#E\">2.2.1 E</a></li><li><a href=\"#F\">2.2.2 F</a><ul><li><a href=\"#G\">2.2.2.1 G</a></li><li><a href=\"#H\">2.2.2.2 H</a></li></ul></ul><li><a href=\"#I\">2.3 I</a></li></ul><li><a href=\"#J\">3 J</a></li><li><a href=\"#K\">4 K</a><ul><ul><li><a href=\"#L\">4.1 L</a></li><li><a href=\"#M\">4.2 M</a><ul><li><a href=\"#N\">4.2.1 N</a></li><li><a href=\"#O\">4.2.2 O</a></li></ul></ul></ul></ul></td></tr></table>") end end