From 00683a2c1e95bb36105d4d0c0fe9bb92faba2227 Mon Sep 17 00:00:00 2001 From: Gal Hammer Date: Mon, 26 Mar 2007 10:10:25 +0000 Subject: [PATCH] Fix and addition to line coloring tests --- Testing/CppUnit/Changes.txt | 4 + .../CppUnit/StringDifferencing/DiffColoring.cpp | 94 +++++++++++++++++++++- Testing/CppUnit/StringDifferencing/DiffColoring.h | 6 ++ 3 files changed, 101 insertions(+), 3 deletions(-) diff --git a/Testing/CppUnit/Changes.txt b/Testing/CppUnit/Changes.txt index 4064f6d44..d0d6dca8f 100644 --- a/Testing/CppUnit/Changes.txt +++ b/Testing/CppUnit/Changes.txt @@ -1,5 +1,9 @@ Testing\selftest\Changes.txt +2007-03-26 Gal + Fix and addition to line coloring tests + StringDifferencing: DiffColoring.cpp DiffColoring.h + 2007-03-21 Gal Fix TestCase1::Difference2 test. StringDifferencing: TestCase1.cpp diff --git a/Testing/CppUnit/StringDifferencing/DiffColoring.cpp b/Testing/CppUnit/StringDifferencing/DiffColoring.cpp index 0bf41f910..9b9048ed9 100644 --- a/Testing/CppUnit/StringDifferencing/DiffColoring.cpp +++ b/Testing/CppUnit/StringDifferencing/DiffColoring.cpp @@ -19,7 +19,7 @@ bool operator==(const wdiff& rdf, const wdiff& ldf) return ((rdf.start[0] == ldf.start[0]) && (rdf.end[0] == ldf.end[0]) && (rdf.start[1] == ldf.start[1]) && - (rdf.start[1] == ldf.start[1])); + (rdf.end[1] == ldf.end[1])); } /** @brief Testcase initialization code. */ @@ -50,7 +50,7 @@ void DiffColoring::OneWord() &diffs); count = diffs.GetSize(); CPPUNIT_ASSERT(count == 1); - CPPUNIT_ASSERT(diffs[0] == wdiff(0, 3, 0, 3)); + CPPUNIT_ASSERT(diffs[0] == wdiff(0, 3, 0, 4)); } /** @@ -73,6 +73,25 @@ void DiffColoring::OneDiff() } /** +* @brief Test word difference in the middle of the line. +*/ +void DiffColoring::OneWordDiff() +{ + wdiffarray diffs; + CString string1(_T("This is the first line")); + CString string2(_T("This is the last line")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(12, 16, 12, 15)); +} + +/** * @brief Test a different string length difference. */ void DiffColoring::DifferentLength() @@ -131,6 +150,62 @@ void DiffColoring::Bug1491334() } /** +* @brief Test punctuation break mode at char level. +*/ +void DiffColoring::PunctuationChar() +{ + wdiffarray diffs; + CString string1(_T("00,52,C8,52")); + CString string2(_T("00,00,00,52")); + int count = 0; + + // Compare case, all white spaces, whitespace break, char level + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, true, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(3, 7, 3, 7)); + + // Compare case, all white spaces, whitespace break + punctuation, char level + diffs.RemoveAll(); + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 1, true, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(3, 7, 3, 7)); +}; + +/** +* @brief Test punctuation break mode at word level. +*/ +void DiffColoring::PunctuationWord() +{ + wdiffarray diffs; + CString string1(_T("00,52,C8,52")); + CString string2(_T("00,00,00,52")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(0, 10, 0, 10)); + + // Compare case, all white spaces, whitespace break + punctuation + diffs.RemoveAll(); + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 1, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(3, 7, 3, 7)); +}; + +/** * @brief Bug #1639453: Imaginary difference highlighted in character level mode. */ void DiffColoring::Bug1639453() @@ -146,7 +221,20 @@ void DiffColoring::Bug1639453() &diffs); count = diffs.GetSize(); CPPUNIT_ASSERT(count == 1); - CPPUNIT_ASSERT(diffs[0] == wdiff(7, 7, 7, 11)); + CPPUNIT_ASSERT(diffs[0] == wdiff(7, 6, 7, 10)); + + // A more complex strings. + string1 = _T("[overlay_oid_origin, overlay_oid_target], [nil, nil]"); + string2 = _T("[overlay_oid_origin, overlay_oid_target, origin_file_name, target_file_name], [nil, nil, \"origin.txt\", \"target.txt\"]"); + + // Compare case, all white spaces, whitespace break + punctuation, char level + diffs.RemoveAll(); + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 1, true, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(39, 50, 39, 114)); } /** diff --git a/Testing/CppUnit/StringDifferencing/DiffColoring.h b/Testing/CppUnit/StringDifferencing/DiffColoring.h index 14030e6a2..a4b01ce81 100644 --- a/Testing/CppUnit/StringDifferencing/DiffColoring.h +++ b/Testing/CppUnit/StringDifferencing/DiffColoring.h @@ -22,8 +22,11 @@ class DiffColoring : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE( DiffColoring ); CPPUNIT_TEST( OneWord ); CPPUNIT_TEST( OneDiff ); + CPPUNIT_TEST( OneWordDiff ); CPPUNIT_TEST( DifferentLength ); CPPUNIT_TEST( DiffWithEmpty ); + CPPUNIT_TEST( PunctuationChar ); + CPPUNIT_TEST( PunctuationWord ); CPPUNIT_TEST( Bug1491334 ); CPPUNIT_TEST( Bug1639453 ); CPPUNIT_TEST( Bug1683061 ); @@ -36,8 +39,11 @@ public: protected: void OneWord(); void OneDiff(); + void OneWordDiff(); void DifferentLength(); void DiffWithEmpty(); + void PunctuationChar(); + void PunctuationWord(); void Bug1491334(); void Bug1639453(); void Bug1683061(); -- 2.11.0