OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 r.clear(); | 1212 r.clear(); |
1213 | 1213 |
1214 SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r); | 1214 SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r); |
1215 EXPECT_EQ(2U, r.size()); | 1215 EXPECT_EQ(2U, r.size()); |
1216 EXPECT_EQ(r[0], L"\ta\t"); | 1216 EXPECT_EQ(r[0], L"\ta\t"); |
1217 EXPECT_EQ(r[1], L"b\tcc"); | 1217 EXPECT_EQ(r[1], L"b\tcc"); |
1218 r.clear(); | 1218 r.clear(); |
1219 } | 1219 } |
1220 | 1220 |
1221 TEST(StringUtilTest, StartsWith) { | 1221 TEST(StringUtilTest, StartsWith) { |
1222 EXPECT_EQ(true, StartsWithASCII("javascript:url", "javascript", true)); | 1222 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true)); |
1223 EXPECT_EQ(true, StartsWithASCII("javascript:url", "javascript", false)); | 1223 EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true)); |
1224 EXPECT_EQ(true, StartsWithASCII("JavaScript:url", "javascript", false)); | 1224 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false)); |
1225 EXPECT_EQ(false, StartsWithASCII("java", "javascript", true)); | 1225 EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false)); |
1226 EXPECT_EQ(false, StartsWithASCII("java", "javascript", false)); | 1226 EXPECT_FALSE(StartsWithASCII("java", "javascript", true)); |
| 1227 EXPECT_FALSE(StartsWithASCII("java", "javascript", false)); |
| 1228 EXPECT_FALSE(StartsWithASCII("", "javascript", false)); |
| 1229 EXPECT_FALSE(StartsWithASCII("", "javascript", true)); |
| 1230 EXPECT_TRUE(StartsWithASCII("java", "", false)); |
| 1231 EXPECT_TRUE(StartsWithASCII("java", "", true)); |
| 1232 |
| 1233 EXPECT_TRUE(StartsWith(L"javascript:url", L"javascript", true)); |
| 1234 EXPECT_FALSE(StartsWith(L"JavaScript:url", L"javascript", true)); |
| 1235 EXPECT_TRUE(StartsWith(L"javascript:url", L"javascript", false)); |
| 1236 EXPECT_TRUE(StartsWith(L"JavaScript:url", L"javascript", false)); |
| 1237 EXPECT_FALSE(StartsWith(L"java", L"javascript", true)); |
| 1238 EXPECT_FALSE(StartsWith(L"java", L"javascript", false)); |
| 1239 EXPECT_FALSE(StartsWith(L"", L"javascript", false)); |
| 1240 EXPECT_FALSE(StartsWith(L"", L"javascript", true)); |
| 1241 EXPECT_TRUE(StartsWith(L"java", L"", false)); |
| 1242 EXPECT_TRUE(StartsWith(L"java", L"", true)); |
1227 } | 1243 } |
1228 | 1244 |
1229 TEST(StringUtilTest, GetStringFWithOffsets) { | 1245 TEST(StringUtilTest, GetStringFWithOffsets) { |
1230 std::vector<size_t> offsets; | 1246 std::vector<size_t> offsets; |
1231 | 1247 |
1232 ReplaceStringPlaceholders(L"Hello, $1. Your number is $2.", L"1", L"2", | 1248 ReplaceStringPlaceholders(L"Hello, $1. Your number is $2.", L"1", L"2", |
1233 &offsets); | 1249 &offsets); |
1234 EXPECT_EQ(2U, offsets.size()); | 1250 EXPECT_EQ(2U, offsets.size()); |
1235 EXPECT_EQ(7U, offsets[0]); | 1251 EXPECT_EQ(7U, offsets[0]); |
1236 EXPECT_EQ(25U, offsets[1]); | 1252 EXPECT_EQ(25U, offsets[1]); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" }, | 1415 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" }, |
1400 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" } | 1416 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" } |
1401 }; | 1417 }; |
1402 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 1418 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
1403 std::wstring output; | 1419 std::wstring output; |
1404 EXPECT_EQ(cases[i].result, | 1420 EXPECT_EQ(cases[i].result, |
1405 ElideString(cases[i].input, cases[i].max_len, &output)); | 1421 ElideString(cases[i].input, cases[i].max_len, &output)); |
1406 EXPECT_TRUE(output == cases[i].output); | 1422 EXPECT_TRUE(output == cases[i].output); |
1407 } | 1423 } |
1408 } | 1424 } |
OLD | NEW |