From 3929fceaf8ebd6eabb7e16526761a1765221f711 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Thu, 18 Dec 2008 22:12:23 -0600 Subject: [PATCH] Fix buglet in xhtmldiff Fixes one of two formely broken unit tests. --- test/unit/diff_test.rb | 20 +++++++++++++------- vendor/plugins/xhtmldiff/lib/xhtmldiff.rb | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/unit/diff_test.rb b/test/unit/diff_test.rb index 5dc204af..77275bfa 100755 --- a/test/unit/diff_test.rb +++ b/test/unit/diff_test.rb @@ -86,6 +86,19 @@ class DiffTest < Test::Unit::TestCase assert_equal "
foo
", diff(a, b) end + def test_diff_for_tag_change + a = "x" + b = "x" + assert_equal "xx", diff(a, b) + end + + def test_diff_for_tag_change_II + a = "" + b = "
    \n
  1. x
  2. \n
  3. y
  4. \n
" + assert_equal "" + + "
    \n
  1. x
  2. \n
  3. y
  4. \n
", 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 = "
a\nb\nc\n
" @@ -94,12 +107,5 @@ class DiffTest < Test::Unit::TestCase "
 a\nb\nc\n
", diff(a, b)) end - - # FIXME. xhtmldiff fails to detect any change here - def test_diff_for_tag_change - a = "x" - b = "x" - assert_equal "xx", diff(a, b) - end end diff --git a/vendor/plugins/xhtmldiff/lib/xhtmldiff.rb b/vendor/plugins/xhtmldiff/lib/xhtmldiff.rb index b3197cea..fd921e1b 100644 --- a/vendor/plugins/xhtmldiff/lib/xhtmldiff.rb +++ b/vendor/plugins/xhtmldiff/lib/xhtmldiff.rb @@ -7,6 +7,7 @@ # Tweaks by Jacques Distler # -- add classnames to and 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)