Refactoring and deleting unused code from lib/diffr.rb until I can understand what it says. Also fixes #256. The build is still broken.
This commit is contained in:
parent
60c07ca1a2
commit
3ea1ef881f
4 changed files with 298 additions and 509 deletions
|
@ -3,90 +3,91 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'diff'
|
||||
|
||||
include Diff
|
||||
|
||||
class DiffTest < Test::Unit::TestCase
|
||||
def test_init
|
||||
assert_nothing_raised {
|
||||
s = SequenceMatcher.new('private Thread currentThread;',
|
||||
'private volatile Thread currentThread;') { |x| x == ' ' }
|
||||
}
|
||||
end
|
||||
|
||||
def test_matching_blocks
|
||||
s = SequenceMatcher.new 'abxcd', 'abcd'
|
||||
assert_equal [[0, 0, 2], [3, 2, 2], [5, 4, 0]], s.get_matching_blocks
|
||||
end
|
||||
|
||||
def test_ratio
|
||||
s = SequenceMatcher.new 'abcd', 'bcde'
|
||||
assert_equal 0.75, s.ratio, 0.001
|
||||
assert_equal 0.75, s.quick_ratio, 0.001
|
||||
assert_equal 1.0, s.real_quick_ratio, 0.001
|
||||
end
|
||||
|
||||
def test_longest_match
|
||||
s = SequenceMatcher.new(' abcd', 'abcd abcd')
|
||||
assert_equal [0, 4, 5], s.find_longest_match(0, 5, 0, 9)
|
||||
end
|
||||
|
||||
def test_opcodes
|
||||
s = SequenceMatcher.new('qabxcd', 'abycdf')
|
||||
assert_equal(
|
||||
[
|
||||
[:delete, 0, 1, 0, 0],
|
||||
[:equal, 1, 3, 0, 2],
|
||||
[:replace, 3, 4, 2, 3],
|
||||
[:equal, 4, 6, 3, 5],
|
||||
[:insert, 6, 6, 5, 6]
|
||||
],
|
||||
s.get_opcodes)
|
||||
|
||||
include HTMLDiff
|
||||
|
||||
def setup
|
||||
@builder = DiffBuilder.new('old', 'new')
|
||||
end
|
||||
|
||||
|
||||
def test_count_leading
|
||||
assert_equal 3, Diff.count_leading(' abc', ' ')
|
||||
def test_start_of_tag
|
||||
assert @builder.start_of_tag?('<')
|
||||
assert(!@builder.start_of_tag?('>'))
|
||||
assert(!@builder.start_of_tag?('a'))
|
||||
end
|
||||
|
||||
def test_html2list
|
||||
a = "here is the original text"
|
||||
def test_end_of_tag
|
||||
assert @builder.end_of_tag?('>')
|
||||
assert(!@builder.end_of_tag?('<'))
|
||||
assert(!@builder.end_of_tag?('a'))
|
||||
end
|
||||
|
||||
def test_whitespace
|
||||
assert @builder.whitespace?(" ")
|
||||
assert @builder.whitespace?("\n")
|
||||
assert @builder.whitespace?("\r")
|
||||
assert(!@builder.whitespace?("a"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_simple
|
||||
assert_equal(
|
||||
['here ', 'is ', 'the ', 'original ', 'text'],
|
||||
HTMLDiff.html2list(a))
|
||||
['the', ' ', 'original', ' ', 'text'],
|
||||
@builder.convert_html_to_list_of_words('the original text'))
|
||||
end
|
||||
|
||||
def test_html_diff
|
||||
a = 'this was the original string'
|
||||
b = 'this is the super string'
|
||||
assert_equal('this <del class="diffmod">was </del>' +
|
||||
'<ins class="diffmod">is </ins>the ' +
|
||||
'<del class="diffmod">original </del>' +
|
||||
'<ins class="diffmod">super </ins>string',
|
||||
HTMLDiff.diff(a, b))
|
||||
def test_convert_html_to_list_of_words_should_separate_endlines
|
||||
assert_equal(
|
||||
['a', "\n", 'b', "\r", 'c'],
|
||||
@builder.convert_html_to_list_of_words("a\nb\rc"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_should_not_compress_whitespace
|
||||
assert_equal(
|
||||
['a', ' ', 'b', ' ', 'c', "\r \n ", 'd'],
|
||||
@builder.convert_html_to_list_of_words("a b c\r \n d"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_should_handle_tags_well
|
||||
assert_equal(
|
||||
['<p>', 'foo', ' ', 'bar', '</p>'],
|
||||
@builder.convert_html_to_list_of_words("<p>foo bar</p>"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_interesting
|
||||
assert_equal(
|
||||
['<p>', 'this', ' ', 'is', '</p>', "\r\n", '<p>', 'the', ' ', 'new', ' ', 'string',
|
||||
'</p>', "\r\n", '<p>', 'around', ' ', 'the', ' ', 'world', '</p>'],
|
||||
@builder.convert_html_to_list_of_words(
|
||||
"<p>this is</p>\r\n<p>the new string</p>\r\n<p>around the world</p>"))
|
||||
end
|
||||
|
||||
def test_html_diff_simple
|
||||
a = 'this was the original string'
|
||||
b = 'this is the new string'
|
||||
assert_equal('this <del class="diffmod">was</del><ins class="diffmod">is</ins> the ' +
|
||||
'<del class="diffmod">original</del><ins class="diffmod">new</ins> string',
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
def test_html_diff_with_multiple_paragraphs
|
||||
a = "<p>this was the original string</p>"
|
||||
b = "<p>this is</p>\r\n<p>the super string</p>\r\n<p>around the world</p>"
|
||||
|
||||
b = "<p>this is</p>\r\n<p>the new string</p>\r\n<p>around the world</p>"
|
||||
assert_equal(
|
||||
"<p>this <del class=\"diffmod\">was </del>" +
|
||||
"<ins class=\"diffmod\">is</ins></p>\r\n<p>the " +
|
||||
"<del class=\"diffmod\">original </del>" +
|
||||
"<ins class=\"diffmod\">super </ins>string</p>\r\n" +
|
||||
"<p><ins class=\"diffins\">around the world</ins></p>",
|
||||
HTMLDiff.diff(a, b)
|
||||
)
|
||||
"<p>this <del class=\"diffmod\">was</del><ins class=\"diffmod\">is</ins></p>\r\n<p> the " +
|
||||
"<del class=\"diffmod\">original </del>" +
|
||||
"<ins class=\"diffmod\">new </ins>string</p>\r\n" +
|
||||
"<p><ins class=\"diffins\">around the world</ins></p>",
|
||||
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>\na\nb\nc\n</pre>"
|
||||
b = ''
|
||||
|
||||
b = "<pre>\n</pre>"
|
||||
assert_equal(
|
||||
"<pre>\n<del class=\"diffdel\">a\nb\nc\n</del></pre>",
|
||||
HTMLDiff.diff(a, b))
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -265,9 +265,8 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
Revision.create(:page => @page, :content => 'What a red and lovely morning today',
|
||||
:author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
|
||||
|
||||
assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " +
|
||||
"</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " +
|
||||
"today</ins></p>", test_renderer(@page.revisions.last).display_diff
|
||||
assert_equal "<p>What a <del class=\"diffmod\">blue</del><ins class=\"diffmod\">red" +
|
||||
"</ins> and lovely morning<ins class=\"diffins\"> today</ins></p>", test_renderer(@page.revisions.last).display_diff
|
||||
end
|
||||
|
||||
def test_link_to_file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue