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 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 r.clear(); | 1240 r.clear(); |
1241 | 1241 |
1242 SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r); | 1242 SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r); |
1243 ASSERT_EQ(2U, r.size()); | 1243 ASSERT_EQ(2U, r.size()); |
1244 EXPECT_EQ(r[0], L"\ta\t"); | 1244 EXPECT_EQ(r[0], L"\ta\t"); |
1245 EXPECT_EQ(r[1], L"b\tcc"); | 1245 EXPECT_EQ(r[1], L"b\tcc"); |
1246 r.clear(); | 1246 r.clear(); |
1247 } | 1247 } |
1248 | 1248 |
1249 // Test for Tokenize | 1249 // Test for Tokenize |
1250 TEST(StringUtilTest, Tokenize) { | 1250 template <typename STR> |
1251 std::vector<std::string> r; | 1251 void TokenizeTest() { |
| 1252 std::vector<STR> r; |
1252 size_t size; | 1253 size_t size; |
1253 | 1254 |
1254 size = Tokenize("This is a string", " ", &r); | 1255 size = Tokenize(STR("This is a string"), STR(" "), &r); |
1255 EXPECT_EQ(4U, size); | 1256 EXPECT_EQ(4U, size); |
1256 ASSERT_EQ(4U, r.size()); | 1257 ASSERT_EQ(4U, r.size()); |
1257 EXPECT_EQ(r[0], "This"); | 1258 EXPECT_EQ(r[0], STR("This")); |
1258 EXPECT_EQ(r[1], "is"); | 1259 EXPECT_EQ(r[1], STR("is")); |
1259 EXPECT_EQ(r[2], "a"); | 1260 EXPECT_EQ(r[2], STR("a")); |
1260 EXPECT_EQ(r[3], "string"); | 1261 EXPECT_EQ(r[3], STR("string")); |
1261 r.clear(); | 1262 r.clear(); |
1262 | 1263 |
1263 size = Tokenize("one,two,three", ",", &r); | 1264 size = Tokenize(STR("one,two,three"), STR(","), &r); |
1264 EXPECT_EQ(3U, size); | 1265 EXPECT_EQ(3U, size); |
1265 ASSERT_EQ(3U, r.size()); | 1266 ASSERT_EQ(3U, r.size()); |
1266 EXPECT_EQ(r[0], "one"); | 1267 EXPECT_EQ(r[0], STR("one")); |
1267 EXPECT_EQ(r[1], "two"); | 1268 EXPECT_EQ(r[1], STR("two")); |
1268 EXPECT_EQ(r[2], "three"); | 1269 EXPECT_EQ(r[2], STR("three")); |
1269 r.clear(); | 1270 r.clear(); |
1270 | 1271 |
1271 size = Tokenize("one,two:three;four", ",:", &r); | 1272 size = Tokenize(STR("one,two:three;four"), STR(",:"), &r); |
1272 EXPECT_EQ(3U, size); | 1273 EXPECT_EQ(3U, size); |
1273 ASSERT_EQ(3U, r.size()); | 1274 ASSERT_EQ(3U, r.size()); |
1274 EXPECT_EQ(r[0], "one"); | 1275 EXPECT_EQ(r[0], STR("one")); |
1275 EXPECT_EQ(r[1], "two"); | 1276 EXPECT_EQ(r[1], STR("two")); |
1276 EXPECT_EQ(r[2], "three;four"); | 1277 EXPECT_EQ(r[2], STR("three;four")); |
1277 r.clear(); | 1278 r.clear(); |
1278 | 1279 |
1279 size = Tokenize("one,two:three;four", ";,:", &r); | 1280 size = Tokenize(STR("one,two:three;four"), STR(";,:"), &r); |
1280 EXPECT_EQ(4U, size); | 1281 EXPECT_EQ(4U, size); |
1281 ASSERT_EQ(4U, r.size()); | 1282 ASSERT_EQ(4U, r.size()); |
1282 EXPECT_EQ(r[0], "one"); | 1283 EXPECT_EQ(r[0], STR("one")); |
1283 EXPECT_EQ(r[1], "two"); | 1284 EXPECT_EQ(r[1], STR("two")); |
1284 EXPECT_EQ(r[2], "three"); | 1285 EXPECT_EQ(r[2], STR("three")); |
1285 EXPECT_EQ(r[3], "four"); | 1286 EXPECT_EQ(r[3], STR("four")); |
1286 r.clear(); | 1287 r.clear(); |
1287 | 1288 |
1288 size = Tokenize("one, two, three", ",", &r); | 1289 size = Tokenize(STR("one, two, three"), STR(","), &r); |
1289 EXPECT_EQ(3U, size); | 1290 EXPECT_EQ(3U, size); |
1290 ASSERT_EQ(3U, r.size()); | 1291 ASSERT_EQ(3U, r.size()); |
1291 EXPECT_EQ(r[0], "one"); | 1292 EXPECT_EQ(r[0], STR("one")); |
1292 EXPECT_EQ(r[1], " two"); | 1293 EXPECT_EQ(r[1], STR(" two")); |
1293 EXPECT_EQ(r[2], " three"); | 1294 EXPECT_EQ(r[2], STR(" three")); |
1294 r.clear(); | 1295 r.clear(); |
1295 | 1296 |
1296 size = Tokenize("one, two, three, ", ",", &r); | 1297 size = Tokenize(STR("one, two, three, "), STR(","), &r); |
1297 EXPECT_EQ(4U, size); | 1298 EXPECT_EQ(4U, size); |
1298 ASSERT_EQ(4U, r.size()); | 1299 ASSERT_EQ(4U, r.size()); |
1299 EXPECT_EQ(r[0], "one"); | 1300 EXPECT_EQ(r[0], STR("one")); |
1300 EXPECT_EQ(r[1], " two"); | 1301 EXPECT_EQ(r[1], STR(" two")); |
1301 EXPECT_EQ(r[2], " three"); | 1302 EXPECT_EQ(r[2], STR(" three")); |
1302 EXPECT_EQ(r[3], " "); | 1303 EXPECT_EQ(r[3], STR(" ")); |
1303 r.clear(); | 1304 r.clear(); |
1304 | 1305 |
1305 size = Tokenize("one, two, three,", ",", &r); | 1306 size = Tokenize(STR("one, two, three,"), STR(","), &r); |
1306 EXPECT_EQ(3U, size); | 1307 EXPECT_EQ(3U, size); |
1307 ASSERT_EQ(3U, r.size()); | 1308 ASSERT_EQ(3U, r.size()); |
1308 EXPECT_EQ(r[0], "one"); | 1309 EXPECT_EQ(r[0], STR("one")); |
1309 EXPECT_EQ(r[1], " two"); | 1310 EXPECT_EQ(r[1], STR(" two")); |
1310 EXPECT_EQ(r[2], " three"); | 1311 EXPECT_EQ(r[2], STR(" three")); |
1311 r.clear(); | 1312 r.clear(); |
1312 | 1313 |
1313 size = Tokenize("", ",", &r); | 1314 size = Tokenize(STR(""), STR(","), &r); |
1314 EXPECT_EQ(0U, size); | 1315 EXPECT_EQ(0U, size); |
1315 ASSERT_EQ(0U, r.size()); | 1316 ASSERT_EQ(0U, r.size()); |
1316 r.clear(); | 1317 r.clear(); |
1317 | 1318 |
1318 size = Tokenize(",", ",", &r); | 1319 size = Tokenize(STR(","), STR(","), &r); |
1319 EXPECT_EQ(0U, size); | 1320 EXPECT_EQ(0U, size); |
1320 ASSERT_EQ(0U, r.size()); | 1321 ASSERT_EQ(0U, r.size()); |
1321 r.clear(); | 1322 r.clear(); |
1322 | 1323 |
1323 size = Tokenize(",;:.", ".:;,", &r); | 1324 size = Tokenize(STR(",;:."), STR(".:;,"), &r); |
1324 EXPECT_EQ(0U, size); | 1325 EXPECT_EQ(0U, size); |
1325 ASSERT_EQ(0U, r.size()); | 1326 ASSERT_EQ(0U, r.size()); |
1326 r.clear(); | 1327 r.clear(); |
1327 | 1328 |
1328 size = Tokenize("\t\ta\t", "\t", &r); | 1329 size = Tokenize(STR("\t\ta\t"), STR("\t"), &r); |
1329 EXPECT_EQ(1U, size); | 1330 EXPECT_EQ(1U, size); |
1330 ASSERT_EQ(1U, r.size()); | 1331 ASSERT_EQ(1U, r.size()); |
1331 EXPECT_EQ(r[0], "a"); | 1332 EXPECT_EQ(r[0], STR("a")); |
1332 r.clear(); | 1333 r.clear(); |
1333 | 1334 |
1334 size = Tokenize("\ta\t\nb\tcc", "\n", &r); | 1335 size = Tokenize(STR("\ta\t\nb\tcc"), STR("\n"), &r); |
1335 EXPECT_EQ(2U, size); | 1336 EXPECT_EQ(2U, size); |
1336 ASSERT_EQ(2U, r.size()); | 1337 ASSERT_EQ(2U, r.size()); |
1337 EXPECT_EQ(r[0], "\ta\t"); | 1338 EXPECT_EQ(r[0], STR("\ta\t")); |
1338 EXPECT_EQ(r[1], "b\tcc"); | 1339 EXPECT_EQ(r[1], STR("b\tcc")); |
1339 r.clear(); | 1340 r.clear(); |
1340 } | 1341 } |
1341 | 1342 |
| 1343 TEST(StringUtilTest, TokenizeStdString) { |
| 1344 TokenizeTest<std::string>(); |
| 1345 } |
| 1346 |
| 1347 TEST(StringUtilTest, TokenizeStringPiece) { |
| 1348 TokenizeTest<base::StringPiece>(); |
| 1349 } |
| 1350 |
1342 // Test for JoinString | 1351 // Test for JoinString |
1343 TEST(StringUtilTest, JoinString) { | 1352 TEST(StringUtilTest, JoinString) { |
1344 std::vector<std::string> in; | 1353 std::vector<std::string> in; |
1345 EXPECT_EQ("", JoinString(in, ',')); | 1354 EXPECT_EQ("", JoinString(in, ',')); |
1346 | 1355 |
1347 in.push_back("a"); | 1356 in.push_back("a"); |
1348 EXPECT_EQ("a", JoinString(in, ',')); | 1357 EXPECT_EQ("a", JoinString(in, ',')); |
1349 | 1358 |
1350 in.push_back("b"); | 1359 in.push_back("b"); |
1351 in.push_back("c"); | 1360 in.push_back("c"); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 SplitStringUsingSubstr( | 1731 SplitStringUsingSubstr( |
1723 "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER", | 1732 "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER", |
1724 "DELIMITER", | 1733 "DELIMITER", |
1725 &results); | 1734 &results); |
1726 ASSERT_EQ(7u, results.size()); | 1735 ASSERT_EQ(7u, results.size()); |
1727 EXPECT_THAT( | 1736 EXPECT_THAT( |
1728 results, ElementsAre("un", "deux", "trois", "quatre", "", "", "")); | 1737 results, ElementsAre("un", "deux", "trois", "quatre", "", "", "")); |
1729 } | 1738 } |
1730 | 1739 |
1731 } // namespace base | 1740 } // namespace base |
OLD | NEW |