Fix buglet in xhtmldiff

Fixes one of two formely broken unit tests.
master
Jacques Distler 2008-12-18 22:12:23 -06:00
parent ad049bcc4b
commit 3929fceaf8
2 changed files with 15 additions and 8 deletions

View File

@ -86,6 +86,19 @@ class DiffTest < Test::Unit::TestCase
assert_equal "<ins class='diffins'><div>foo</div></ins>", diff(a, b)
end
def test_diff_for_tag_change
a = "<a>x</a>"
b = "<b>x</b>"
assert_equal "<del class='diffmod'><a>x</a></del><ins class='diffmod'><b>x</b></ins>", diff(a, b)
end
def test_diff_for_tag_change_II
a = "<ul>\n<li>x</li>\n<li>y</li>\n</ul>"
b = "<ol>\n<li>x</li>\n<li>y</li>\n</ol>"
assert_equal "<del class='diffmod'><ul>\n<li>x</li>\n<li>y</li>\n</ul>" +
"</del><ins class='diffmod'><ol>\n<li>x</li>\n<li>y</li>\n</ol></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>"
@ -94,12 +107,5 @@ class DiffTest < Test::Unit::TestCase
"<pre><span> a\n<del class='diffdel'>b\nc\n</del></span></pre>",
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>"
assert_equal "<del class='diffdel'><a>x</a></del><ins class='diffins'><b>x</b></ins>", diff(a, b)
end
end

View File

@ -7,6 +7,7 @@
# Tweaks by Jacques Distler <distler@golem.ph.utexas.edu>
# -- add classnames to <del> and <ins> elements added by XHTMLDiff,
# for better CSS styling
# -- detect change in element name, without change in content
require 'diff/lcs'
require 'rexml/document'
@ -64,7 +65,7 @@ class XHTMLDiff
if a == b
return a.deep_clone
end
if REXML::HashableElementDelegator === a and REXML::HashableElementDelegator === b
if REXML::HashableElementDelegator === a and REXML::HashableElementDelegator === b and a.name == b.name
o = REXML::Element.new(a.name)
o.add_attributes a.attributes
hd = self.new(o)