Skip to content
Snippets Groups Projects
Commit 99cbfc26 authored by Jamie Oliver's avatar Jamie Oliver
Browse files

Use semantic equivalence for HTML tests. Fixes gollum/gollum#649

parent 50ffcb42
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
# required by pry
s.add_development_dependency('rb-readline', '~> 0.4.2')
s.add_development_dependency 'minitest-reporters', '~> 0.14.10'
s.add_development_dependency('nokogiri-diff', '~> 0.1.2')
 
# = MANIFEST =
s.files = %w[
Loading
Loading
# ~*~ encoding: utf-8 ~*~
require 'nokogiri'
require 'nokogiri/diff'
def assert_html_equal(expected, actual, msg = nil)
msg = build_message(msg, "? expected to be HTML equivalent to ?.", expected, actual)
assert_block(msg) do
expected_doc = Nokogiri::HTML(expected) { |config| config.noblanks }
actual_doc = Nokogiri::HTML(actual) { |config| config.noblanks }
expected_doc.diff(actual_doc) do |change, node|
break if change != ' '
end
end
end
# ~*~ encoding: utf-8 ~*~
require 'rubygems'
# stdlib
require 'test/unit'
require 'fileutils'
# external
require 'rubygems'
require 'shoulda'
require 'mocha/setup'
require 'fileutils'
require 'minitest/reporters'
 
# internal
require File.expand_path('../assertions', __FILE__)
MiniTest::Reporters.use!
 
dir = File.dirname(File.expand_path(__FILE__))
Loading
Loading
Loading
Loading
@@ -172,28 +172,28 @@ context "Markup" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
 
page = @wiki.page("Bilbo Baggins")
assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
assert_html_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
end
 
test "page link with different text" do
@wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details)
page = @wiki.page("Potato")
output = page.formatted_data
assert_equal "<p>a<aclass=\"internalpresent\"href=\"/Potato\">PotatoHeaad</a></p>", normal(output)
assert_html_equal "<p>a<aclass=\"internalpresent\"href=\"/Potato\">PotatoHeaad</a></p>", normal(output)
end
 
test "page link with different text on mediawiki" do
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
page = @wiki.page("Potato")
output = page.formatted_data
assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>
assert_html_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>
"), normal(output)
end
 
test "wiki link within inline code block" do
@wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details)
page = @wiki.page("Potato")
assert_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
assert_html_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
end
 
test "regexp gsub! backref (#383)" do
Loading
Loading
@@ -209,7 +209,7 @@ context "Markup" do
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<pre><code> <div class=\"highlight\"><pre><span class=\"n\">rot13</span><span class=\"o\">=</span><span class=\"err\">'</span><span class=\"n\">tr</span> <span class=\"sc\">'\\''</span><span class=\"n\">A</span><span class=\"o\">-</span><span class=\"n\">Za</span><span class=\"o\">-</span><span class=\"n\">z</span><span class=\"sc\">'\\''</span> <span class=\"sc\">'\\''</span><span class=\"n\">N</span><span class=\"o\">-</span><span class=\"n\">ZA</span><span class=\"o\">-</span><span class=\"n\">Mn</span><span class=\"o\">-</span><span class=\"n\">za</span><span class=\"o\">-</span><span class=\"n\">m</span><span class=\"err\">'\\'</span>\n</pre></div>\n</code></pre>}
assert_equal expected, output
assert_html_equal expected, output
end
 
# Issue #568
Loading
Loading
@@ -222,7 +222,7 @@ context "Markup" do
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"err\">'</span><span class=\"n\">hi</span><span class=\"err\">'</span>\n</pre></div>}
assert_equal expected, output
assert_html_equal expected, output
end
 
test "tilde code blocks #537" do
Loading
Loading
@@ -234,7 +234,7 @@ context "Markup" do
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
assert_equal expected, output
assert_html_equal expected, output
end
 
# Issue #537
Loading
Loading
@@ -247,7 +247,7 @@ context "Markup" do
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
assert_equal expected, output
assert_html_equal expected, output
end
 
# Issue #537
Loading
Loading
@@ -261,7 +261,7 @@ context "Markup" do
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"o\">~~</span>\n<span class=\"s1\">'hi'</span><span class=\"o\">~</span>\n</pre></div>}
assert_equal expected, output
assert_html_equal expected, output
end
 
test "four space indented code block" do
Loading
Loading
@@ -271,19 +271,19 @@ context "Markup" do
test), commit_details)
output = @wiki.page(page).formatted_data
expected = %(<pre><code>test\ntest\n</code></pre>)
assert_equal expected, output
assert_html_equal expected, output
end
 
test "wiki link within code block" do
@wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
page = @wiki.page("Potato")
assert_equal "<pre><code>sed -i '' 's/[[:space:]]*$//'\n</code></pre>", page.formatted_data
assert_html_equal "<pre><code>sed -i '' 's/[[:space:]]*$//'\n</code></pre>", page.formatted_data
end
 
test "piped wiki link within code block" do
@wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details)
page = @wiki.page("Potato")
assert_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
assert_html_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
end
 
#########################################################################
Loading
Loading
@@ -299,7 +299,7 @@ context "Markup" do
 
page = @wiki.page(name)
output = page.formatted_data
assert_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.jpg\" /> b</p>}, output
assert_html_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.jpg\" /> b</p>}, output
end
end
 
Loading
Loading
@@ -310,7 +310,7 @@ context "Markup" do
 
page = @wiki.page(name)
output = page.formatted_data
assert_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.JPG\" /> b</p>}, output
assert_html_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.JPG\" /> b</p>}, output
end
end
 
Loading
Loading
@@ -322,7 +322,7 @@ context "Markup" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
 
page = @wiki.page("Bilbo Baggins")
assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
assert_html_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
end
 
test "image with relative path on root" do
Loading
Loading
@@ -333,7 +333,7 @@ context "Markup" do
index.commit("Add alpha.jpg")
 
page = @wiki.page("Bilbo Baggins")
assert_equal %Q{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
assert_html_equal %Q{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
end
 
test "image with relative path" do
Loading
Loading
@@ -345,7 +345,7 @@ context "Markup" do
 
page = @wiki.page("Bilbo Baggins")
output = page.formatted_data
assert_equal %{<p>a <img src=\"/wiki/greek/alpha.jpg\" /><a href=\"/wiki/greek/alpha.jpg\">a</a> b</p>}, output
assert_html_equal %{<p>a <img src=\"/wiki/greek/alpha.jpg\" /><a href=\"/wiki/greek/alpha.jpg\">a</a> b</p>}, output
end
 
test "image with absolute path on a preview" do
Loading
Loading
@@ -355,7 +355,7 @@ context "Markup" do
index.commit("Add alpha.jpg")
 
page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown)
assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /> b</p>}, page.formatted_data
assert_html_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /> b</p>}, page.formatted_data
end
 
test "image with relative path on a preview" do
Loading
Loading
@@ -366,7 +366,7 @@ context "Markup" do
index.commit("Add alpha.jpg")
 
page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown)
assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><img src=\"/wiki/greek/alpha.jpg\" /> b</p>}, page.formatted_data
assert_html_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><img src=\"/wiki/greek/alpha.jpg\" /> b</p>}, page.formatted_data
end
 
test "image with alt" do
Loading
Loading
@@ -455,7 +455,7 @@ context "Markup" do
 
page = @wiki.page("Bilbo Baggins")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <a href="/alpha.jpg">Alpha</a> b</p>}, output
assert_html_equal %{<p>a <a href="/alpha.jpg">Alpha</a> b</p>}, output
end
 
test "file link with relative path" do
Loading
Loading
@@ -466,7 +466,7 @@ context "Markup" do
 
page = @wiki.page("Bilbo Baggins")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>}, output
assert_html_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>}, output
end
 
test "file link with external path" do
Loading
Loading
@@ -475,7 +475,7 @@ context "Markup" do
index.commit("Add alpha.jpg")
 
page = @wiki.page("Bilbo Baggins")
assert_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
assert_html_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
end
 
#########################################################################
Loading
Loading
@@ -494,7 +494,7 @@ context "Markup" do
 
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_html_equal output, rendered
end
 
test "code blocks with carriage returns" do
Loading
Loading
@@ -507,7 +507,7 @@ context "Markup" do
 
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_html_equal output, rendered
end
 
test "code blocks with two-space indent" do
Loading
Loading
@@ -537,7 +537,7 @@ context "Markup" do
 
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render(false, 'utf-8')
assert_equal output, rendered
assert_html_equal output, rendered
end
 
test "code blocks with ascii characters" do
Loading
Loading
@@ -586,7 +586,7 @@ np.array([[2,2],[1,3]],np.float)
 
page = @wiki.page("a")
output = page.formatted_data
assert_equal %Q{<p>a\nFile not found: /base</p>}, output
assert_html_equal %Q{<p>a\nFile not found: /base</p>}, output
end
 
test "embed code page relative link" do
Loading
Loading
@@ -595,7 +595,7 @@ np.array([[2,2],[1,3]],np.float)
 
page = @wiki.page("a")
output = page.formatted_data
assert_equal %Q{<p>a\nFile not found: base</p>}, output
assert_html_equal %Q{<p>a\nFile not found: base</p>}, output
end
 
test "code block in unsupported language" do
Loading
Loading
@@ -603,7 +603,7 @@ np.array([[2,2],[1,3]],np.float)
 
page = @wiki.page("a")
output = page.formatted_data
assert_equal %Q{<p>a\ncode\nb</p>}, output
assert_html_equal %Q{<p>a\ncode\nb</p>}, output
end
 
#########################################################################
Loading
Loading
@@ -642,7 +642,7 @@ if $METADATA ##################################################################
 
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_html_equal output, rendered
assert_equal result, page.metadata
end
 
Loading
Loading
@@ -657,7 +657,7 @@ if $METADATA ##################################################################
 
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_html_equal output, rendered
assert_equal result, page.metadata
end
 
Loading
Loading
@@ -672,7 +672,7 @@ if $METADATA ##################################################################
 
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_html_equal output, rendered
assert_equal result, page.metadata
end
end # if $METADATA
Loading
Loading
@@ -775,11 +775,11 @@ if ENV['ASCIIDOC']
# Asciidoc
#########################################################################
 
test "asciidoc header" do
test "asciidoc header" do
compare("= Book Title\n\n== Heading", '<div class="sect1"><h2 id="wiki-_heading">Heading<a class="anchor" id="Heading" href="#Heading"></a></h2><div class="sectionbody"></div></div>', 'asciidoc')
end
 
test "internal links with asciidoc" do
test "internal links with asciidoc" do
compare("= Book Title\n\n[[anid]]\n== Heading", '<div class="sect1"><h2 id="wiki-anid">Heading<a class="anchor" id="Heading" href="#Heading"></a></h2><div class="sectionbody"></div></div>', 'asciidoc')
end
end
Loading
Loading
@@ -803,7 +803,7 @@ end
page, rendered = render_page(content, ext)
 
if regexes.empty?
assert_equal normal(output), normal(rendered)
assert_html_equal normal(output), normal(rendered)
else
output = page.formatted_data
regexes.each { |r| assert_match r, output }
Loading
Loading
@@ -819,6 +819,6 @@ end
@wiki.clear_cache
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal normal(output), normal(rendered)
assert_html_equal normal(output), normal(rendered)
end
end
Loading
Loading
@@ -27,14 +27,14 @@ context "remote_code" do
 
# we expect
expected = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"nt\">&lt;ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">&gt;</span>\n <span class=\"nt\">&lt;li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">&gt;</span>\n <span class=\"nt\">&lt;a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">&gt;&lt;span</span> <span class=\"na\">class=</span><span class=\"s\">\"icon\"</span><span class=\"nt\">&gt;&lt;/span&gt;</span>0<span class=\"nt\">&lt;/a&gt;</span>\n <span class=\"nt\">&lt;/li&gt;</span>\n<span class=\"nt\">&lt;/ol&gt;</span>\n</pre></div>\n\n<p>b</p>}
assert_equal expected, rendered
assert_html_equal expected, rendered
end
 
test 'contents' do
g = Gollum::RemoteCode.new 'https://raw.github.com/gollum/gollum-lib/master/test/file_view/1_file.txt'
 
expected = %{<ol class=\"tree\">\n <li class=\"file\">\n <a href=\"0\"><span class=\"icon\"></span>0</a>\n </li>\n</ol>\n}
assert_equal expected, g.contents
assert_html_equal expected, g.contents
end
 
test "remote_code relative local file" do
Loading
Loading
@@ -48,7 +48,7 @@ context "remote_code" do
@wiki.clear_cache
 
output = page.formatted_data
assert_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
assert_html_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
end
 
test "remote_code relative local file in subdir" do
Loading
Loading
@@ -60,14 +60,14 @@ context "remote_code" do
 
page = @wiki.paged('Pippin', 'foo')
output = page.formatted_data
assert_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
assert_html_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
end
 
test "remote_code relative no file" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:no-file-exists.py```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
output = page.formatted_data
assert_equal %Q{<p>a\nFile not found: no-file-exists.py\nb</p>}, output
assert_html_equal %Q{<p>a\nFile not found: no-file-exists.py\nb</p>}, output
end
 
test "remote_code absolute local file" do
Loading
Loading
@@ -80,21 +80,21 @@ context "remote_code" do
@wiki.clear_cache
 
output = page.formatted_data
assert_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span>\n</pre></div>\n\n<p>b</p>}, output
assert_html_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span>\n</pre></div>\n\n<p>b</p>}, output
end
 
test "remote_code absolute no file" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:/monkey/no-file-exists.py```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
output = page.formatted_data
assert_equal %Q{<p>a\nFile not found: /monkey/no-file-exists.py\nb</p>}, output
assert_html_equal %Q{<p>a\nFile not found: /monkey/no-file-exists.py\nb</p>}, output
end
 
test "remote_code error generates santized html" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:<script>foo</script>```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
output = page.formatted_data
assert_equal %Q{<p>a\nFile not found: &lt;script&gt;foo&lt;/script&gt;\nb</p>}, output
assert_html_equal %Q{<p>a\nFile not found: &lt;script&gt;foo&lt;/script&gt;\nb</p>}, output
end
 
teardown do
Loading
Loading
Loading
Loading
@@ -123,7 +123,7 @@ context "Wiki page previewing" do
test "preview_page" do
page = @wiki.preview_page("Test", "# Bilbo", :markdown)
assert_equal "# Bilbo", page.raw_data
assert_equal %Q{<h1>Bilbo<a class=\"anchor\" id=\"Bilbo\" href=\"#Bilbo\"></a></h1>}, page.formatted_data
assert_html_equal %Q{<h1>Bilbo<a class=\"anchor\" id=\"Bilbo\" href=\"#Bilbo\"></a></h1>}, page.formatted_data
assert_equal "Test.md", page.filename
assert_equal "Test", page.name
end
Loading
Loading
@@ -139,8 +139,8 @@ context "Wiki TOC" do
test "toc_generation" do
page = @wiki.preview_page("Test", "# Bilbo", :markdown)
assert_equal "# Bilbo", page.raw_data
assert_equal '<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a></h1>', page.formatted_data.gsub(/\n/,"")
assert_equal %{<div class="toc"><div class="toc-title">Table of Contents</div><ul><li><a href="#Bilbo">Bilbo</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
assert_html_equal '<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a></h1>', page.formatted_data
assert_html_equal %{<div class="toc"><div class="toc-title">Table of Contents</div><ul><li><a href="#Bilbo">Bilbo</a></li></ul></div>}, page.toc_data
end
 
# Ensure ' creates valid links in TOC
Loading
Loading
@@ -149,8 +149,8 @@ context "Wiki TOC" do
test "' in link" do
page = @wiki.preview_page("Test", "# a'b", :markdown)
assert_equal "# a'b", page.raw_data
assert_equal %q{<h1>a'b<a class="anchor" id="a'b" href="#a'b"></a></h1>}, page.formatted_data.gsub(/\n/,"")
assert_equal %{<div class=\"toc\"><div class=\"toc-title\">Table of Contents</div><ul><li><a href=\"#a'b\">a'b</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
assert_html_equal %q{<h1>a'b<a class="anchor" id="a'b" href="#a'b"></a></h1>}, page.formatted_data
assert_html_equal %{<div class=\"toc\"><div class=\"toc-title\">Table of Contents</div><ul><li><a href=\"#a'b\">a'b</a></li></ul></div>}, page.toc_data
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment