diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-10 08:18:46 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-10 08:18:46 +0000 |
commit | 4493574d71becba0ad1cbb74ce600466cc4f33e0 (patch) | |
tree | f50e1a49a49043de9e134087cb98f3b337fdf3b1 /base/string_util_unittest.cc | |
parent | a15cbd47814d62163e2d66e64e7cb9e144fa5ca1 (diff) | |
download | chromium_src-4493574d71becba0ad1cbb74ce600466cc4f33e0.zip chromium_src-4493574d71becba0ad1cbb74ce600466cc4f33e0.tar.gz chromium_src-4493574d71becba0ad1cbb74ce600466cc4f33e0.tar.bz2 |
Make the glob matcher support UTF8 strings.
This generalizes the existing pattern matching code to support UTF8 strings.
BUG=53158
TEST=string_util_unittests.cc
Review URL: http://codereview.chromium.org/3295018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util_unittest.cc')
-rw-r--r-- | base/string_util_unittest.cc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index f0524bee..23b1f53 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1064,22 +1064,36 @@ TEST(StringUtilTest, SplitStringAlongWhitespace) { } TEST(StringUtilTest, MatchPatternTest) { - EXPECT_EQ(MatchPatternASCII("www.google.com", "*.com"), true); - EXPECT_EQ(MatchPatternASCII("www.google.com", "*"), true); - EXPECT_EQ(MatchPatternASCII("www.google.com", "www*.g*.org"), false); - EXPECT_EQ(MatchPatternASCII("Hello", "H?l?o"), true); - EXPECT_EQ(MatchPatternASCII("www.google.com", "http://*)"), false); - EXPECT_EQ(MatchPatternASCII("www.msn.com", "*.COM"), false); - EXPECT_EQ(MatchPatternASCII("Hello*1234", "He??o\\*1*"), true); - EXPECT_EQ(MatchPatternASCII("", "*.*"), false); - EXPECT_EQ(MatchPatternASCII("", "*"), true); - EXPECT_EQ(MatchPatternASCII("", "?"), true); - EXPECT_EQ(MatchPatternASCII("", ""), true); - EXPECT_EQ(MatchPatternASCII("Hello", ""), false); - EXPECT_EQ(MatchPatternASCII("Hello*", "Hello*"), true); + EXPECT_TRUE(MatchPattern("www.google.com", "*.com")); + EXPECT_TRUE(MatchPattern("www.google.com", "*")); + EXPECT_FALSE(MatchPattern("www.google.com", "www*.g*.org")); + EXPECT_TRUE(MatchPattern("Hello", "H?l?o")); + EXPECT_FALSE(MatchPattern("www.google.com", "http://*)")); + EXPECT_FALSE(MatchPattern("www.msn.com", "*.COM")); + EXPECT_TRUE(MatchPattern("Hello*1234", "He??o\\*1*")); + EXPECT_FALSE(MatchPattern("", "*.*")); + EXPECT_TRUE(MatchPattern("", "*")); + EXPECT_TRUE(MatchPattern("", "?")); + EXPECT_TRUE(MatchPattern("", "")); + EXPECT_FALSE(MatchPattern("Hello", "")); + EXPECT_TRUE(MatchPattern("Hello*", "Hello*")); // Stop after a certain recursion depth. - EXPECT_EQ(MatchPatternASCII("12345678901234567890", "???????????????????*"), - false); + EXPECT_FALSE(MatchPattern("123456789012345678", "?????????????????*")); + + // Test UTF8 matching. + EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0", "*\xe2\x99\xa0")); + EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0.", "heart: ?.")); + EXPECT_TRUE(MatchPattern("hearts: \xe2\x99\xa0\xe2\x99\xa0", "*")); + // Invalid sequences should be handled as a single invalid character. + EXPECT_TRUE(MatchPattern("invalid: \xef\xbf\xbe", "invalid: ?")); + // If the pattern has invalid characters, it shouldn't match anything. + EXPECT_FALSE(MatchPattern("\xf4\x90\x80\x80", "\xf4\x90\x80\x80")); + + // Test UTF16 character matching. + EXPECT_TRUE(MatchPattern(UTF8ToUTF16("www.google.com"), + UTF8ToUTF16("*.com"))); + EXPECT_TRUE(MatchPattern(UTF8ToUTF16("Hello*1234"), + UTF8ToUTF16("He??o\\*1*"))); } TEST(StringUtilTest, LcpyTest) { |