#!/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
diff_doc << (div = REXML::Element.new 'div' )
hd = XHTMLDiff.new(div)
parsed_a = REXML::HashableElementDelegator.new(
REXML::XPath.first(REXML::Document.new("
"+a+"
"), '/div'))
parsed_b = REXML::HashableElementDelegator.new(
REXML::XPath.first(REXML::Document.new(""+b+"
"), '/div'))
Diff::LCS.traverse_balanced(parsed_a, parsed_b, hd)
diffs = ''
diff_doc.write(diffs, -1, true, true)
diffs
end
def test_html_diff_simple
a = 'this was the original string'
b = 'this is the new string'
assert_equal(" this was is the" +
" original new string
",
diff(a, b))
end
def test_html_diff_with_multiple_paragraphs
a = "this was the original string
"
b = "this is
\n the new string
\naround the world
"
assert_equal(
" this was is" +
" the original string
" +
"
\n the new string
" +
"
\naround the world
",
diff(a, b))
end
def test_split_paragraph_into_two
a = "foo bar
"
b = "foo
bar
"
assert_equal(
"",
diff(a,b))
end
def test_join_two_paragraphs_into_one
a = "foo
bar
"
b = "foo bar
"
assert_equal(
"",
diff(a,b))
end
def test_add_inline_element
a = "foo bar
"
b = "foo bar
"
assert_equal(
"",
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
"
b = "a\n
"
assert_equal(
"",
diff(a, b))
end
def test_html_diff_with_tags
a = ""
b = "foo
"
assert_equal "", diff(a, b)
end
def test_diff_for_tag_change
a = "x"
b = "x"
# FIXME sad, but true - this case produces an invalid XML. If handle this you can, strong your foo is.
assert_equal "", diff(a, b)
end
end