More fixes, sync with HTML5lib
Do a better job with the wrapper <div>s added by xhtmldiff and Maruku's to_html_tree method. More tests fixed.
This commit is contained in:
parent
3ca33e52b5
commit
3de374d6c1
20 changed files with 541 additions and 118 deletions
|
@ -11,7 +11,9 @@ class DiffTest < Test::Unit::TestCase
|
|||
|
||||
def diff(a,b)
|
||||
diff_doc = REXML::Document.new
|
||||
diff_doc << (div = REXML::Element.new 'div' )
|
||||
div = REXML::Element.new('div', nil, {:respect_whitespace =>:all})
|
||||
div.attributes['class'] = 'xhtmldiff_wrapper'
|
||||
diff_doc << div
|
||||
hd = XHTMLDiff.new(div)
|
||||
parsed_a = REXML::HashableElementDelegator.new(
|
||||
REXML::XPath.first(REXML::Document.new("<div>"+a+"</div>"), '/div'))
|
||||
|
@ -20,14 +22,14 @@ class DiffTest < Test::Unit::TestCase
|
|||
Diff::LCS.traverse_balanced(parsed_a, parsed_b, hd)
|
||||
diffs = ''
|
||||
diff_doc.write(diffs, -1, true, true)
|
||||
diffs
|
||||
diffs.gsub(/\A<div class='xhtmldiff_wrapper'>(.*)<\/div>\Z/m, '\1')
|
||||
end
|
||||
|
||||
def test_html_diff_simple
|
||||
a = 'this was the original string'
|
||||
b = 'this is the new string'
|
||||
assert_equal("<div><span> this<del class='diffmod'> was</del><ins class='diffmod'> is</ins> the" +
|
||||
"<del class='diffmod'> original</del><ins class='diffmod'> new</ins> string</span></div>",
|
||||
assert_equal("<span> this<del class='diffmod'> was</del><ins class='diffmod'> is</ins> the" +
|
||||
"<del class='diffmod'> original</del><ins class='diffmod'> new</ins> string</span>",
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
|
@ -35,10 +37,10 @@ class DiffTest < Test::Unit::TestCase
|
|||
a = "<p>this was the original string</p>"
|
||||
b = "<p>this is</p>\n<p> the new string</p>\n<p>around the world</p>"
|
||||
assert_equal(
|
||||
"<div><p><span> this<del class='diffmod'> was</del><ins class='diffmod'> is</ins>" +
|
||||
"<p><span> this<del class='diffmod'> was</del><ins class='diffmod'> is</ins>" +
|
||||
"<del class='diffdel'> the</del><del class='diffdel'> original</del><del class='diffdel'> string</del></span></p>" +
|
||||
"<ins class='diffins'>\n</ins><ins class='diffins'><p> the new string</p></ins>" +
|
||||
"<ins class='diffins'>\n</ins><ins class='diffins'><p>around the world</p></ins></div>",
|
||||
"<ins class='diffins'>\n</ins><ins class='diffins'><p>around the world</p></ins>",
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
|
@ -46,8 +48,8 @@ class DiffTest < Test::Unit::TestCase
|
|||
a = "<p>this is a paragraph</p>\n<p>this is a second paragraph</p>\n<p>this is a third paragraph</p>"
|
||||
b = "<p>this is a paragraph</p>\n<p>this is a third paragraph</p>"
|
||||
assert_equal(
|
||||
"<div><p>this is a paragraph</p>\n<del class='diffdel'><p>this is a second paragraph</p></del>" +
|
||||
"<del class='diffdel'>\n</del><p>this is a third paragraph</p></div>",
|
||||
"<p>this is a paragraph</p>\n<del class='diffdel'><p>this is a second paragraph</p></del>" +
|
||||
"<del class='diffdel'>\n</del><p>this is a third paragraph</p>",
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
|
@ -55,8 +57,8 @@ class DiffTest < Test::Unit::TestCase
|
|||
a = "<p>foo bar</p>"
|
||||
b = "<p>foo</p><p>bar</p>"
|
||||
assert_equal(
|
||||
"<div><p><span> foo<del class='diffdel'> bar</del></span></p>" +
|
||||
"<ins class='diffins'><p>bar</p></ins></div>",
|
||||
"<p><span> foo<del class='diffdel'> bar</del></span></p>" +
|
||||
"<ins class='diffins'><p>bar</p></ins>",
|
||||
diff(a,b))
|
||||
end
|
||||
|
||||
|
@ -64,8 +66,8 @@ class DiffTest < Test::Unit::TestCase
|
|||
a = "<p>foo</p><p>bar</p>"
|
||||
b = "<p>foo bar</p>"
|
||||
assert_equal(
|
||||
"<div><p><span> foo<ins class='diffins'> bar</ins></span></p>" +
|
||||
"<del class='diffdel'><p>bar</p></del></div>",
|
||||
"<p><span> foo<ins class='diffins'> bar</ins></span></p>" +
|
||||
"<del class='diffdel'><p>bar</p></del>",
|
||||
diff(a,b))
|
||||
end
|
||||
|
||||
|
@ -73,31 +75,31 @@ class DiffTest < Test::Unit::TestCase
|
|||
a = "<p>foo bar</p>"
|
||||
b = "<p>foo <b>bar</b></p>"
|
||||
assert_equal(
|
||||
"<div><p><span> foo<del class='diffdel'> bar</del></span>" +
|
||||
"<ins class='diffins'><b>bar</b></ins></p></div>",
|
||||
"<p><span> foo<del class='diffdel'> bar</del></span>" +
|
||||
"<ins class='diffins'><b>bar</b></ins></p>",
|
||||
diff(a,b))
|
||||
end
|
||||
|
||||
def test_html_diff_with_tags
|
||||
a = ""
|
||||
b = "<div>foo</div>"
|
||||
assert_equal "<ins class='diffins'><div>foo</div></ins>", diff(a, b)
|
||||
end
|
||||
|
||||
# FIXME this test fails (ticket #67, http://dev.instiki.org/ticket/67)
|
||||
def test_html_diff_preserves_endlines_in_pre
|
||||
a = "<pre>a\nb\nc\n</pre>"
|
||||
b = "<pre>a\n</pre>"
|
||||
assert_equal(
|
||||
"<div><pre><span> a\n<del class='diffdel'>b\nc\n</del></span></pre></div>",
|
||||
"<pre><span> a\n<del class='diffdel'>b\nc\n</del></span></pre>",
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
def test_html_diff_with_tags
|
||||
a = ""
|
||||
b = "<div>foo</div>"
|
||||
assert_equal "<div><ins class='diffins'><div>foo</div></ins></div>", diff(a, b)
|
||||
end
|
||||
|
||||
# FIXME. xhtmldiff fails to detect any change here
|
||||
def test_diff_for_tag_change
|
||||
a = "<a>x</a>"
|
||||
b = "<b>x</b>"
|
||||
# FIXME. xhtmldiff fails to detect any change here
|
||||
assert_equal "<div><del class='diffdel'><a>x</a></del><ins class='diffins'><b>x</b></ins></div>", diff(a, b)
|
||||
assert_equal "<del class='diffdel'><a>x</a></del><ins class='diffins'><b>x</b></ins>", diff(a, b)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
68
test/unit/maruku_tex.rb
Executable file
68
test/unit/maruku_tex.rb
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RedClothForTexTest < Test::Unit::TestCase
|
||||
def test_basics
|
||||
assert_equal '{\bf First Page}', Maruku.new('*First Page*').to_latex
|
||||
assert_equal '{\em First Page}', Maruku.new('_First Page_').to_latex
|
||||
assert_equal "\\begin{itemize}\n\t\\item A\n\t\t\\item B\n\t\t\\item C\n\t\\end{itemize}", Maruku.new('* A\n* B\n* C').to_latex
|
||||
end
|
||||
|
||||
def test_blocks
|
||||
assert_equal '\section*{hello}', Maruku.new('#hello#').to_latex
|
||||
assert_equal '\subsection*{hello}', Maruku.new('##hello##').to_latex
|
||||
end
|
||||
|
||||
def test_table_of_contents
|
||||
|
||||
source = <<EOL
|
||||
* [[A]]
|
||||
** [[B]]
|
||||
** [[C]]
|
||||
* D
|
||||
** [[E]]
|
||||
*** F
|
||||
EOL
|
||||
|
||||
expected_result = <<EOL
|
||||
\\pagebreak
|
||||
|
||||
\\section{A}
|
||||
Abe
|
||||
|
||||
\\subsection{B}
|
||||
Babe
|
||||
|
||||
\\subsection{C}
|
||||
\\pagebreak
|
||||
|
||||
\\section{D}
|
||||
|
||||
\\subsection{E}
|
||||
|
||||
\\subsubsection{F}
|
||||
EOL
|
||||
expected_result.chop!
|
||||
assert_equal(expected_result, table_of_contents(source, 'A' => 'Abe', 'B' => 'Babe'))
|
||||
end
|
||||
|
||||
def test_entities
|
||||
assert_equal "Beck \\& Fowler are 100\\% cool", RedClothForTex.new("Beck & Fowler are 100% cool").to_tex
|
||||
end
|
||||
|
||||
def test_bracket_links
|
||||
assert_equal "such a Horrible Day, but I won't be Made Useless", RedClothForTex.new("such a [[Horrible Day]], but I won't be [[Made Useless]]").to_tex
|
||||
end
|
||||
|
||||
def test_footnotes_on_abbreviations
|
||||
assert_equal(
|
||||
"such a Horrible Day\\footnote{1}, but I won't be Made Useless",
|
||||
RedClothForTex.new("such a [[Horrible Day]][1], but I won't be [[Made Useless]]").to_tex
|
||||
)
|
||||
end
|
||||
|
||||
def test_subsection_depth
|
||||
assert_equal "\\subsubsection*{Hello}", RedClothForTex.new("h4. Hello").to_tex
|
||||
end
|
||||
end
|
|
@ -57,12 +57,12 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
set_web_property :markup, :markdown
|
||||
|
||||
assert_markup_parsed_as(
|
||||
%{<h1>My Headline</h1>\n\n<p>that <span class="newWikiWord">} +
|
||||
%{<h1 id="my_headline">My Headline</h1>\n\n<p>that <span class="newWikiWord">} +
|
||||
%{Smart Engine GUI<a href="../show/SmartEngineGUI">?</a></span></p>},
|
||||
"My Headline\n===========\n\nthat SmartEngineGUI")
|
||||
|
||||
assert_markup_parsed_as(
|
||||
%{<h1>My Headline</h1>\n\n<p>that <span class="newWikiWord">} +
|
||||
%{<h1 id="my_headline">My Headline</h1>\n\n<p>that <span class="newWikiWord">} +
|
||||
%{Smart Engine GUI<a href="../show/SmartEngineGUI">?</a></span></p>},
|
||||
"#My Headline#\n\nthat SmartEngineGUI")
|
||||
|
||||
|
@ -77,7 +77,7 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
assert_markup_parsed_as(
|
||||
%{<p>This is a code block:</p>\n\n<pre><code>def a_method(arg)\n} +
|
||||
%{return ThatWay\n</code></pre>\n\n<p>Nice!</p>},
|
||||
%{return ThatWay</code></pre>\n\n<p>Nice!</p>},
|
||||
code_block)
|
||||
end
|
||||
|
||||
|
@ -105,15 +105,15 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
|
||||
set_web_property :markup, :markdown
|
||||
assert_markup_parsed_as(
|
||||
"<h1>Markdown heading</h1>\n\n" +
|
||||
"<h1 id=\"markdown_heading\">Markdown heading</h1>\n\n" +
|
||||
"<p>h2. Textile heading</p>\n\n" +
|
||||
"<p><em>some</em> <strong>text</strong> <em>with</em> -styles-</p>\n\n" +
|
||||
"<ul>\n<li>list 1</li>\n<li>list 2</li>\n</ul>",
|
||||
"<ul>\n<li>list 1</li>\n\n<li>list 2</li>\n</ul>",
|
||||
textile_and_markdown)
|
||||
|
||||
set_web_property :markup, :textile
|
||||
assert_markup_parsed_as(
|
||||
"<p>Markdown heading<br />================</p>\n\n\n\t<h2>Textile heading</h2>" +
|
||||
"<p>Markdown heading<br/>================</p>\n\n\n\t<h2>Textile heading</h2>" +
|
||||
"\n\n\n\t<p><strong>some</strong> <b>text</b> <em>with</em> <del>styles</del></p>" +
|
||||
"\n\n\n\t<ul>\n\t<li>list 1</li>\n\t\t<li>list 2</li>\n\t</ul>",
|
||||
textile_and_markdown)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue