#!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../test_helper') require 'diff' class DiffTest < Test::Unit::TestCase include HTMLDiff def setup @builder = DiffBuilder.new('old', 'new') end def test_start_of_tag assert @builder.start_of_tag?('<') assert(!@builder.start_of_tag?('>')) assert(!@builder.start_of_tag?('a')) end 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( ['the', ' ', 'original', ' ', 'text'], @builder.convert_html_to_list_of_words('the original text')) end 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( ['
', 'foo', ' ', 'bar', '
'], @builder.convert_html_to_list_of_words("foo bar
")) end def test_convert_html_to_list_of_words_interesting assert_equal( ['', 'this', ' ', 'is', '
', "\r\n", '', 'the', ' ', 'new', ' ', 'string', '
', "\r\n", '', 'around', ' ', 'the', ' ', 'world', '
'], @builder.convert_html_to_list_of_words( "this is
\r\nthe new string
\r\naround the world
")) end def test_html_diff_simple a = 'this was the original string' b = 'this is the new string' assert_equal('thisthis was the original string
" b = "this is
\r\nthe new string
\r\naround the world
" # Some of this expected result is accidental to implementation. # At least it's well-formed and more or less correct. assert_equal( "this wasis
the " +
"originalnew" +
" string
around the world
", 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 = "\na\nb\nc\n" b = "
\n" assert_equal( "
\n", diff(a, b)) end def test_html_diff_with_tags a = "" b = "a\nb\nc\n