| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <math.h> | 5 #include <math.h> |
| 6 #include <stdarg.h> | 6 #include <stdarg.h> |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 | 918 |
| 919 TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSigns) { | 919 TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSigns) { |
| 920 std::vector<std::string> subst; | 920 std::vector<std::string> subst; |
| 921 subst.push_back("a"); | 921 subst.push_back("a"); |
| 922 subst.push_back("b"); | 922 subst.push_back("b"); |
| 923 subst.push_back("c"); | 923 subst.push_back("c"); |
| 924 EXPECT_EQ(ReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst, NULL), | 924 EXPECT_EQ(ReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst, NULL), |
| 925 "$1 $$2 $$$3"); | 925 "$1 $$2 $$$3"); |
| 926 } | 926 } |
| 927 | 927 |
| 928 TEST(StringUtilTest, SplitStringAlongWhitespace) { | |
| 929 struct TestData { | |
| 930 const std::wstring input; | |
| 931 const size_t expected_result_count; | |
| 932 const std::wstring output1; | |
| 933 const std::wstring output2; | |
| 934 } data[] = { | |
| 935 { L"a", 1, L"a", L"" }, | |
| 936 { L" ", 0, L"", L"" }, | |
| 937 { L" a", 1, L"a", L"" }, | |
| 938 { L" ab ", 1, L"ab", L"" }, | |
| 939 { L" ab c", 2, L"ab", L"c" }, | |
| 940 { L" ab c ", 2, L"ab", L"c" }, | |
| 941 { L" ab cd", 2, L"ab", L"cd" }, | |
| 942 { L" ab cd ", 2, L"ab", L"cd" }, | |
| 943 { L" \ta\t", 1, L"a", L"" }, | |
| 944 { L" b\ta\t", 2, L"b", L"a" }, | |
| 945 { L" b\tat", 2, L"b", L"at" }, | |
| 946 { L"b\tat", 2, L"b", L"at" }, | |
| 947 { L"b\t at", 2, L"b", L"at" }, | |
| 948 }; | |
| 949 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | |
| 950 std::vector<std::wstring> results; | |
| 951 SplitStringAlongWhitespace(data[i].input, &results); | |
| 952 ASSERT_EQ(data[i].expected_result_count, results.size()); | |
| 953 if (data[i].expected_result_count > 0) | |
| 954 ASSERT_EQ(data[i].output1, results[0]); | |
| 955 if (data[i].expected_result_count > 1) | |
| 956 ASSERT_EQ(data[i].output2, results[1]); | |
| 957 } | |
| 958 } | |
| 959 | |
| 960 TEST(StringUtilTest, MatchPatternTest) { | 928 TEST(StringUtilTest, MatchPatternTest) { |
| 961 EXPECT_TRUE(MatchPattern("www.google.com", "*.com")); | 929 EXPECT_TRUE(MatchPattern("www.google.com", "*.com")); |
| 962 EXPECT_TRUE(MatchPattern("www.google.com", "*")); | 930 EXPECT_TRUE(MatchPattern("www.google.com", "*")); |
| 963 EXPECT_FALSE(MatchPattern("www.google.com", "www*.g*.org")); | 931 EXPECT_FALSE(MatchPattern("www.google.com", "www*.g*.org")); |
| 964 EXPECT_TRUE(MatchPattern("Hello", "H?l?o")); | 932 EXPECT_TRUE(MatchPattern("Hello", "H?l?o")); |
| 965 EXPECT_FALSE(MatchPattern("www.google.com", "http://*)")); | 933 EXPECT_FALSE(MatchPattern("www.google.com", "http://*)")); |
| 966 EXPECT_FALSE(MatchPattern("www.msn.com", "*.COM")); | 934 EXPECT_FALSE(MatchPattern("www.msn.com", "*.COM")); |
| 967 EXPECT_TRUE(MatchPattern("Hello*1234", "He??o\\*1*")); | 935 EXPECT_TRUE(MatchPattern("Hello*1234", "He??o\\*1*")); |
| 968 EXPECT_FALSE(MatchPattern("", "*.*")); | 936 EXPECT_FALSE(MatchPattern("", "*.*")); |
| 969 EXPECT_TRUE(MatchPattern("", "*")); | 937 EXPECT_TRUE(MatchPattern("", "*")); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 EXPECT_FALSE(ContainsOnlyChars("Hello", "")); | 1106 EXPECT_FALSE(ContainsOnlyChars("Hello", "")); |
| 1139 | 1107 |
| 1140 EXPECT_TRUE(ContainsOnlyChars("", "1234")); | 1108 EXPECT_TRUE(ContainsOnlyChars("", "1234")); |
| 1141 EXPECT_TRUE(ContainsOnlyChars("1", "1234")); | 1109 EXPECT_TRUE(ContainsOnlyChars("1", "1234")); |
| 1142 EXPECT_TRUE(ContainsOnlyChars("1", "4321")); | 1110 EXPECT_TRUE(ContainsOnlyChars("1", "4321")); |
| 1143 EXPECT_TRUE(ContainsOnlyChars("123", "4321")); | 1111 EXPECT_TRUE(ContainsOnlyChars("123", "4321")); |
| 1144 EXPECT_FALSE(ContainsOnlyChars("123a", "4321")); | 1112 EXPECT_FALSE(ContainsOnlyChars("123a", "4321")); |
| 1145 } | 1113 } |
| 1146 | 1114 |
| 1147 } // namespace base | 1115 } // namespace base |
| OLD | NEW |