From 2e7bd548ab8cfe422cddb3df342c62e4fd6ccc80 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 27 Feb 2009 23:15:50 +0000 Subject: [PATCH] Tests: Add few more unit tests for string differencing. --- .../GoogleTest/StringDiffs/stringdiffs_test.cpp | 109 ++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/Testing/GoogleTest/StringDiffs/stringdiffs_test.cpp b/Testing/GoogleTest/StringDiffs/stringdiffs_test.cpp index 112d605a5..d11f8dcc8 100644 --- a/Testing/GoogleTest/StringDiffs/stringdiffs_test.cpp +++ b/Testing/GoogleTest/StringDiffs/stringdiffs_test.cpp @@ -43,13 +43,118 @@ namespace // Objects declared here can be used by all tests in the test case for Foo. }; - TEST_F(StringDiffsTest, Identical1) + // sd_ComputeWordDiffs() parameters are: + // String & str1 - the first string to compare + // String & str2 - the second string to compare + // bool case_sensitive - is the compare case-sensitive? + // int whitespace - do we ignore whitespace and how + // int breakType - word (0) or char (1) break + // bool byte_level - are we word (false) or byte-level (true) diffing + // std::vector * pDiffs - resultting diff list + + // Identical strings, no case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, Default1) + { + std::vector diffs; + sd_ComputeWordDiffs("abcde", "abcde", false, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } + + // Identical strings, no case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, DefaultDiffererentLen) + { + std::vector diffs; + sd_ComputeWordDiffs("abcdef", "abcde", false, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 1); + } + + // Identical strings, no case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, DefaultWhitespaceEnd) + { + std::vector diffs; + sd_ComputeWordDiffs("abcde ", "abcde", false, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 1); + } + + // Identical strings, case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, Caseignore1) { std::vector diffs; - sd_ComputeWordDiffs("Boo", "Boo", true, 0, 0, false, &diffs); + sd_ComputeWordDiffs("abcde", "abcde", true, 0, 0, false, &diffs); EXPECT_TRUE(diffs.size() == 0); } + // Identical strings, case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, CaseignoreCase1) + { + std::vector diffs; + sd_ComputeWordDiffs("aBcde", "abcde", true, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 1); + } + + // Identical strings, case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, CaseignoreWhitespace1) + { + std::vector diffs; + sd_ComputeWordDiffs("aBcde ", "abcde", true, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 2); + } + + // Identical strings, case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, CaseignoreWhitespace2) + { + std::vector diffs; + sd_ComputeWordDiffs("aBcde", " abcde", true, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 2); + } + + // Identical strings, no case sensitivity, ignore whitespace change, words, word-level + TEST_F(StringDiffsTest, CaseignoreWhitespace3) + { + std::vector diffs; + sd_ComputeWordDiffs("abcde abcde", "abcde abcde", false, 1, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } + + // Identical strings, no case sensitivity, ignore whitespace change, words, word-level + TEST_F(StringDiffsTest, CaseignoreWhitespace4) + { + std::vector diffs; + sd_ComputeWordDiffs(" abcde abcde", " abcde abcde", false, 1, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } + + // Identical strings, no case sensitivity, ignore whitespace change, words, word-level + TEST_F(StringDiffsTest, CaseignoreWhitespace5) + { + std::vector diffs; + sd_ComputeWordDiffs(" abcde abcde", " abcde abcde", false, 1, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } + + // Identical strings, no case sensitivity, ignore whitespace change, words, word-level + TEST_F(StringDiffsTest, CaseignoreWhitespace6) + { + std::vector diffs; + sd_ComputeWordDiffs(" abcde abcde", "abcde abcde", false, 1, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } + + // Identical strings, case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, Identical2) + { + std::vector diffs; + sd_ComputeWordDiffs("abcde", "abcde", true, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } + + // Case-differing strings, no case sensitivity, no whitespace, words, word-level + TEST_F(StringDiffsTest, Identical3) + { + std::vector diffs; + sd_ComputeWordDiffs("aBcde", "abcDe", false, 0, 0, false, &diffs); + EXPECT_TRUE(diffs.size() == 0); + } } // namespace -- 2.11.0