test/wiki_cloth_test.rb in wikicloth-0.6.3 vs test/wiki_cloth_test.rb in wikicloth-0.7.0
- old
+ new
@@ -1,8 +1,13 @@
+# encoding: utf-8
require File.expand_path(File.join(File.dirname(__FILE__),'test_helper'))
class WikiParser < WikiCloth::Parser
+ url_for do |page|
+ page
+ end
+
template do |template|
case template
when "noinclude"
"<noinclude>hello world</noinclude><includeonly>testing</includeonly>"
when "test"
@@ -13,27 +18,70 @@
"{{{def|hello world}}} {{{1}}} {{{test}}} {{{nested|{{{2}}}}}}"
when "moreparamtest"
"{{{{{test|bla}}|wtf}}}"
when "loop"
"{{loop}}"
+ when "tablebegin"
+ "<table>"
+ when "tablemid"
+ "<tr><td>test</td></tr>"
+ when "tableend"
+ "</table>"
end
end
external_link do |url,text|
"<a href=\"#{url}\" target=\"_blank\" class=\"exlink\">#{text.blank? ? url : text}</a>"
end
end
class WikiClothTest < ActiveSupport::TestCase
+ test "math tag" do
+ wiki = WikiParser.new(:data => "<math>1-\frac{k}{|E(G_j)|}</math>")
+ begin
+ data = wiki.to_html
+ assert true
+ rescue
+ assert false
+ end
+ end
+
test "links and references" do
wiki = WikiCloth::Parser.new(:data => File.open(File.join(File.dirname(__FILE__), '../sample_documents/george_washington.wiki'), READ_MODE) { |f| f.read })
data = wiki.to_html
assert wiki.external_links.size == 38
assert wiki.references.size == 76
- assert wiki.internal_links.size == 450
+ assert wiki.internal_links.size == 322
+ assert wiki.categories.size == 27
+ assert wiki.languages.size == 101
end
+
+ test "links with imbedded links" do
+ wiki = WikiParser.new(:data => "[[Datei:Schulze and Gerard 01.jpg|miniatur|Klaus Schulze während eines Konzerts mit [[Lisa Gerrard]]]] hello world")
+ data = wiki.to_html
+ assert data =~ /Lisa Gerrard/
+ end
+
+ test "links with trailing letters" do
+ wiki = WikiParser.new(:data => "[[test]]s [[rawr]]alot [[some]]thi.ng [[a]] space")
+ data = wiki.to_html
+ assert data =~ /tests/
+ assert data =~ /href="test"/
+ assert data =~ /rawralot/
+ assert data !~ /something/
+ assert data !~ /aspace/
+ end
+ test "piped links with trailing letters" do
+ wiki = WikiParser.new(:data => "[[a|b]]c [[b|c]]d<nowiki>e</nowiki>")
+ data = wiki.to_html
+ assert data =~ /bc/
+ assert data =~ /href="a"/
+ assert data =~ /cd/
+ assert data !~ /cde/
+ end
+
test "Embedded images with no explicit title" do
wiki = WikiParser.new(:data => "[[Image:Rectangular coordinates.svg|left|thumb|250px]]")
test = true
begin
data = wiki.to_html
@@ -105,10 +153,17 @@
wiki = WikiParser.new(:data => "{{moreparamtest|p=othervar|busted=whoo}}")
data = wiki.to_html
assert data =~ /whoo/
end
+
+ test "table spanning template" do
+ wiki = WikiParser.new(:data => "{{tablebegin}}{{tablemid}}{{tableend}}")
+ data = wiki.to_html
+ puts data
+ assert data =~ /test/
+ end
test "horizontal rule" do
wiki = WikiParser.new(:data => "----\n")
data = wiki.to_html
assert data =~ /hr/
@@ -134,11 +189,11 @@
# should == 6.. 3 <li>'s and 3 </li>'s
data.gsub(/li/) { |ret|
count += 1
ret
}
- assert count == 6
+ assert_equal count.to_s, "6"
end
test "noinclude and includeonly tags" do
wiki = WikiParser.new(:data => "<noinclude>main page</noinclude><includeonly>never seen</includeonly>{{noinclude}}\n")
data = wiki.to_html
@@ -171,13 +226,13 @@
end
test "disable edit stuff" do
wiki = WikiParser.new(:data => "= Hallo =")
data = wiki.to_html
- assert_equal data, "<p>\n<h1><span class=\"editsection\">[<a href=\"?section=Hallo\" title=\"Edit section: Hallo\">edit</a>]</span> <span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
+ assert_equal data, "\n<p><h1><span class=\"editsection\">[<a href=\"?section=Hallo\" title=\"Edit section: Hallo\">edit</a>]</span> <span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
data = wiki.to_html(:noedit => true)
- assert_equal data, "<p>\n<h1><span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
+ assert_equal data, "\n<p><h1><span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
end
end