#!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../test_helper') require 'xhtmldiff' class DiffTest < Test::Unit::TestCase def setup end def diff(a,b) diff_doc = REXML::Document.new 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("
this was the original string
" b = "this is
\nthe new string
\naround the world
" assert_equal( " this was is" +
" the original string
the new string
" + "\naround the world
", diff(a, b)) end def test_html_diff_deleting_a_paragraph a = "this is a paragraph
\nthis is a second paragraph
\nthis is a third paragraph
" b = "this is a paragraph
\nthis is a third paragraph
" assert_equal( "this is a paragraph
\nthis is a second paragraph
this is a third paragraph
", diff(a, b)) end def test_split_paragraph_into_two a = "foo bar
" b = "foo
bar
" assert_equal( " foo bar
bar
", diff(a,b)) end def test_join_two_paragraphs_into_one a = "foo
bar
" b = "foo bar
" assert_equal( "foo bar
" + "bar
foo bar
" b = "foo bar
" assert_equal( " foo bar" +
"bar
a\nb\nc\n" b = "
a\n" assert_equal( "
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 "