Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: base/string_util_unittest.cc

Issue 1039001: HttpRequestHeaders refactor. (Closed)
Patch Set: Fix bugs, add tests. Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/string_util.cc ('k') | net/http/http_network_transaction.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
17 using ::testing::ElementsAre;
18
16 namespace base { 19 namespace base {
17 20
18 namespace { 21 namespace {
19 22
20 // Given a null-terminated string of wchar_t with each wchar_t representing 23 // Given a null-terminated string of wchar_t with each wchar_t representing
21 // a UTF-16 code unit, returns a string16 made up of wchar_t's in the input. 24 // a UTF-16 code unit, returns a string16 made up of wchar_t's in the input.
22 // Each wchar_t should be <= 0xFFFF and a non-BMP character (> U+FFFF) 25 // Each wchar_t should be <= 0xFFFF and a non-BMP character (> U+FFFF)
23 // should be represented as a surrogate pair (two UTF-16 units) 26 // should be represented as a surrogate pair (two UTF-16 units)
24 // *even* where wchar_t is 32-bit (Linux and Mac). 27 // *even* where wchar_t is 32-bit (Linux and Mac).
25 // 28 //
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 EXPECT_TRUE(ContainsOnlyChars("", "")); 1488 EXPECT_TRUE(ContainsOnlyChars("", ""));
1486 EXPECT_FALSE(ContainsOnlyChars("Hello", "")); 1489 EXPECT_FALSE(ContainsOnlyChars("Hello", ""));
1487 1490
1488 EXPECT_TRUE(ContainsOnlyChars("", "1234")); 1491 EXPECT_TRUE(ContainsOnlyChars("", "1234"));
1489 EXPECT_TRUE(ContainsOnlyChars("1", "1234")); 1492 EXPECT_TRUE(ContainsOnlyChars("1", "1234"));
1490 EXPECT_TRUE(ContainsOnlyChars("1", "4321")); 1493 EXPECT_TRUE(ContainsOnlyChars("1", "4321"));
1491 EXPECT_TRUE(ContainsOnlyChars("123", "4321")); 1494 EXPECT_TRUE(ContainsOnlyChars("123", "4321"));
1492 EXPECT_FALSE(ContainsOnlyChars("123a", "4321")); 1495 EXPECT_FALSE(ContainsOnlyChars("123a", "4321"));
1493 } 1496 }
1494 1497
1495 } // base 1498 TEST(SplitStringUsingSubstrTest, EmptyString) {
1499 std::vector<std::string> results;
1500 SplitStringUsingSubstr("", "DELIMITER", &results);
1501 ASSERT_EQ(1u, results.size());
1502 EXPECT_THAT(results, ElementsAre(""));
1503 }
1504
1505 TEST(SplitStringUsingSubstrTest, StringWithNoDelimiter) {
1506 std::vector<std::string> results;
1507 SplitStringUsingSubstr("alongwordwithnodelimiter", "DELIMITER", &results);
1508 ASSERT_EQ(1u, results.size());
1509 EXPECT_THAT(results, ElementsAre("alongwordwithnodelimiter"));
1510 }
1511
1512 TEST(SplitStringUsingSubstrTest, LeadingDelimitersSkipped) {
1513 std::vector<std::string> results;
1514 SplitStringUsingSubstr(
1515 "DELIMITERDELIMITERDELIMITERoneDELIMITERtwoDELIMITERthree",
1516 "DELIMITER",
1517 &results);
1518 ASSERT_EQ(6u, results.size());
1519 EXPECT_THAT(results, ElementsAre("", "", "", "one", "two", "three"));
1520 }
1521
1522 TEST(SplitStringUsingSubstrTest, ConsecutiveDelimitersSkipped) {
1523 std::vector<std::string> results;
1524 SplitStringUsingSubstr(
1525 "unoDELIMITERDELIMITERDELIMITERdosDELIMITERtresDELIMITERDELIMITERcuatro",
1526 "DELIMITER",
1527 &results);
1528 ASSERT_EQ(7u, results.size());
1529 EXPECT_THAT(results, ElementsAre("uno", "", "", "dos", "tres", "", "cuatro"));
1530 }
1531
1532 TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) {
1533 std::vector<std::string> results;
1534 SplitStringUsingSubstr(
1535 "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER",
1536 "DELIMITER",
1537 &results);
1538 ASSERT_EQ(7u, results.size());
1539 EXPECT_THAT(
1540 results, ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
1541 }
1542
1543 } // namespace base
OLDNEW
« no previous file with comments | « base/string_util.cc ('k') | net/http/http_network_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698