Esempio n. 1
0
/**
 * @brief Test we handle simple case difference correctly.
 * This function tests we handle one-char case difference correctly
 * with different compare options. In this test the difference is
 * in the middle of word.
 */
void DifferentStrings1::CasesDiffer2()
{
	wdiffarray diffs;
	CString string1(_T("test"));
	CString string2(_T("teSt"));
	int count = 0;

	// Compare case, all whitespaces, whitespace break
	// We must find one difference
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 1);

	// Ignore case, all whitespaces, whitespace break
	// No difference
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		false, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 0);

	// Compare case, whitespaces change, whitespace break
	// We must find one difference
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_IGNORE_CHANGE, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 1);

	// Compare case, whitespaces ignore, whitespace break
	// We must find one difference
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_IGNORE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 1);
}
Esempio n. 2
0
/**
 * @brief Test identical words are detected as such.
 * This function tests that two identical words are detected
 * as identical with different word-compare settings.
 */
void TestCase1::Identical1()
{
	wdiffarray diffs;
	CString string1(_T("Test"));
	CString string2(_T("Test"));
	int count = 0;

	// Compare case, all whitespaces, whitespace break
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 0);

	// Ignore case, all whitespaces, whitespace break
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		false, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 0);

	// Compare case, whitespaces change, whitespace break
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_IGNORE_CHANGE, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 0);

	// Compare case, whitespaces ignore, whitespace break
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_IGNORE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 0);
}
Esempio n. 3
0
/**
 * @brief Test different words are detected as such.
 * This function tests that two different words are detected
 * as different with different word-compare settings.
 */
void TestCase1::Difference1()
{
	wdiffarray diffs;
	CString string1(_T("Test"));
	CString string2(_T("test"));
	int count = 0;

	// Break type is whitespace or punctuation

	// Check strings with different settings
	sd_ComputeWordDiffs(string1, string2,
		false, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 0);
	diffs.RemoveAll();

	// Check strings with different settings
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 1);
	diffs.RemoveAll();

	// Check strings with different settings
	string1 = _T("tesT");
	string2 = _T("test");
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_COMPARE_ALL, 0, false,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT_MESSAGE(_T("testT & test difference not found!"), count == 1);
	diffs.RemoveAll();
}
Esempio n. 4
0
/**
* @brief Bug #1683061: Bug in highlighting.
*/
void DiffColoring::Bug1683061()
{
	wdiffarray diffs;
	CString string1(_T("ABC"));
	CString string2(_T("ABCD"));
	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, 2, 0, 3));

	// Compare case, all white spaces, whitespace break + punctuation
	diffs.RemoveAll();
	sd_ComputeWordDiffs(string1, string2,
		true, WHITESPACE_COMPARE_ALL, 0, true,
		&diffs);
	count = diffs.GetSize();
	CPPUNIT_ASSERT(count == 1);
	CPPUNIT_ASSERT(diffs[0] == wdiff(3, 2, 3, 3));
}
Esempio n. 5
0
/**
* @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));
};
Esempio n. 6
0
int main(int argc, const char* argv[]) {
    std::string string1("Testing the comparision functions.");
    std::string string2("Hello");
    std::string string3("stinger");
    std::string string4(string2);

    std::cout << "string1: " << string1 << "\nstring2: " << string2
              << "\nstring3: " << string3 << "\nstring4: " << string4 << "\n\n";

    // comparing string1 and string4
    if (string1 == string4)
        std::cout << "string1 == string4\n";
    else {
        if (string1 > string4)
            std::cout << "string1 > string4\n";
        else
            std::cout << "string1 < string4\n";
    }

    // comparing string1 and string2
    int result = string1.compare(string2);

    if (result == 0)
        std::cout << "string1.compare(string2) == 0\n";
    else {
        if (result > 0)
            std::cout << "string1.compare(string2) > 0\n";
        else
            std::cout << "string1.compare(string2) < 0\n";
    }

    // comparing string1 (elements 2-5) and string3 (elements 0-5)
    result = string1.compare(2, 5, string3, 0, 5);

    if (result == 0)
        std::cout << "string1.compare(2, 5, string3, 0, 5) == 0\n";
    else {
        if (result > 0)
            std::cout << "string1.compare(2, 5, string3, 0, 5) > 0\n";
        else
            std::cout << "string1.compare(2, 5, string3, 0, 5) < 0\n";
    }

    // comparing string2 and string4
    result = string4.compare(0, string2.length(), string2);

    if (result == 0)
        std::cout << "string4.compare(0, string2.length(), string2) == 0"
                  << std::endl;
    else {
        if (result > 0)
            std::cout << "string4.compare(0, string2.length(), string2) > 0"
                      << std::endl;
        else
            std::cout << "string4.compare(0, string2.length(), string2) < 0"
                      << std::endl;
    }

    // comparing string2 and string4
    result = string2.compare(0, 3, string4);

    if (result == 0)
        std::cout << "string2.compare(0, 3, string4) == 0" << std::endl;
    else {
        if (result > 0)
            std::cout << "string2.compare(0, 3, string4) > 0" << std::endl;
        else
            std::cout << "string2.compare(0, 3, string4) < 0" << std::endl;
    }

    return 0;
}