| Index: chrome/browser/autocomplete/autocomplete_match_unittest.cc
|
| diff --git a/chrome/browser/autocomplete/autocomplete_match_unittest.cc b/chrome/browser/autocomplete/autocomplete_match_unittest.cc
|
| index b8fe4ed61b35c9f25026e51c2e8a72168ed706e8..1d0e4d2de4e821b1570aca4b1c48a4739dc1f5cb 100644
|
| --- a/chrome/browser/autocomplete/autocomplete_match_unittest.cc
|
| +++ b/chrome/browser/autocomplete/autocomplete_match_unittest.cc
|
| @@ -31,3 +31,73 @@ TEST(AutocompleteMatchTest, MoreRelevant) {
|
| AutocompleteMatch::MoreRelevant(m1, m2));
|
| }
|
| }
|
| +
|
| +TEST(AutocompleteMatchTest, MergeClassifications) {
|
| + // Merging two empty vectors should result in an empty vector.
|
| + EXPECT_EQ(std::string(),
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ACMatchClassifications(),
|
| + AutocompleteMatch::ACMatchClassifications())));
|
| +
|
| + // If one vector is empty and the other is "trivial" but non-empty (i.e. (0,
|
| + // NONE)), the non-empty vector should be returned.
|
| + EXPECT_EQ("0,0",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString("0,0"),
|
| + AutocompleteMatch::ACMatchClassifications())));
|
| + EXPECT_EQ("0,0",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ACMatchClassifications(),
|
| + AutocompleteMatch::ClassificationsFromString("0,0"))));
|
| +
|
| + // Ditto if the one-entry vector is non-trivial.
|
| + EXPECT_EQ("0,1",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString("0,1"),
|
| + AutocompleteMatch::ACMatchClassifications())));
|
| + EXPECT_EQ("0,1",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ACMatchClassifications(),
|
| + AutocompleteMatch::ClassificationsFromString("0,1"))));
|
| +
|
| + // Merge an unstyled one-entry vector with a styled one-entry vector.
|
| + EXPECT_EQ("0,1",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString("0,0"),
|
| + AutocompleteMatch::ClassificationsFromString("0,1"))));
|
| +
|
| + // Test simple cases of overlap.
|
| + EXPECT_EQ("0,3," "1,2",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString("0,1," "1,0"),
|
| + AutocompleteMatch::ClassificationsFromString("0,2"))));
|
| + EXPECT_EQ("0,3," "1,2",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString("0,2"),
|
| + AutocompleteMatch::ClassificationsFromString("0,1," "1,0"))));
|
| +
|
| + // Test the case where both vectors have classifications at the same
|
| + // positions.
|
| + EXPECT_EQ("0,3",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString("0,1," "1,2"),
|
| + AutocompleteMatch::ClassificationsFromString("0,2," "1,1"))));
|
| +
|
| + // Test an arbitrary complicated case.
|
| + EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0",
|
| + AutocompleteMatch::ClassificationsToString(
|
| + AutocompleteMatch::MergeClassifications(
|
| + AutocompleteMatch::ClassificationsFromString(
|
| + "0,0," "2,1," "4,3," "7,7," "10,6," "15,0"),
|
| + AutocompleteMatch::ClassificationsFromString(
|
| + "0,2," "1,0," "5,7," "6,1," "17,0"))));
|
| +}
|
|
|