OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/quic/platform/api/quic_text_utils.h" | 5 #include "net/quic/platform/api/quic_text_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_piece.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
11 | 10 |
12 using base::StringPiece; | |
13 using std::string; | 11 using std::string; |
14 | 12 |
15 namespace net { | 13 namespace net { |
16 namespace test { | 14 namespace test { |
17 | 15 |
18 TEST(QuicTextUtilsText, StartsWith) { | 16 TEST(QuicTextUtilsText, StartsWith) { |
19 EXPECT_TRUE(QuicTextUtils::StartsWith("hello world", "hello")); | 17 EXPECT_TRUE(QuicTextUtils::StartsWith("hello world", "hello")); |
20 EXPECT_TRUE(QuicTextUtils::StartsWith("hello world", "hello world")); | 18 EXPECT_TRUE(QuicTextUtils::StartsWith("hello world", "hello world")); |
21 EXPECT_TRUE(QuicTextUtils::StartsWith("hello world", "")); | 19 EXPECT_TRUE(QuicTextUtils::StartsWith("hello world", "")); |
22 EXPECT_FALSE(QuicTextUtils::StartsWith("hello world", "Hello")); | 20 EXPECT_FALSE(QuicTextUtils::StartsWith("hello world", "Hello")); |
(...skipping 15 matching lines...) Expand all Loading... |
38 EXPECT_EQ("lower", QuicTextUtils::ToLower("lOwEr")); | 36 EXPECT_EQ("lower", QuicTextUtils::ToLower("lOwEr")); |
39 EXPECT_EQ("123", QuicTextUtils::ToLower("123")); | 37 EXPECT_EQ("123", QuicTextUtils::ToLower("123")); |
40 EXPECT_EQ("", QuicTextUtils::ToLower("")); | 38 EXPECT_EQ("", QuicTextUtils::ToLower("")); |
41 } | 39 } |
42 | 40 |
43 TEST(QuicTextUtilsText, RemoveLeadingAndTrailingWhitespace) { | 41 TEST(QuicTextUtilsText, RemoveLeadingAndTrailingWhitespace) { |
44 string input; | 42 string input; |
45 | 43 |
46 for (auto* input : {"text", " text", " text", "text ", "text ", " text ", | 44 for (auto* input : {"text", " text", " text", "text ", "text ", " text ", |
47 " text ", "\r\n\ttext", "text\n\r\t"}) { | 45 " text ", "\r\n\ttext", "text\n\r\t"}) { |
48 StringPiece piece(input); | 46 QuicStringPiece piece(input); |
49 QuicTextUtils::RemoveLeadingAndTrailingWhitespace(&piece); | 47 QuicTextUtils::RemoveLeadingAndTrailingWhitespace(&piece); |
50 EXPECT_EQ("text", piece); | 48 EXPECT_EQ("text", piece); |
51 } | 49 } |
52 } | 50 } |
53 | 51 |
54 TEST(QuicTextUtilsText, StringToNumbers) { | 52 TEST(QuicTextUtilsText, StringToNumbers) { |
55 const string kMaxInt32Plus1 = "2147483648"; | 53 const string kMaxInt32Plus1 = "2147483648"; |
56 const string kMinInt32Minus1 = "-2147483649"; | 54 const string kMinInt32Minus1 = "-2147483649"; |
57 const string kMaxUint32Plus1 = "4294967296"; | 55 const string kMaxUint32Plus1 = "4294967296"; |
58 | 56 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 181 |
184 TEST(QuicTextUtilsText, ContainsUpperCase) { | 182 TEST(QuicTextUtilsText, ContainsUpperCase) { |
185 EXPECT_FALSE(QuicTextUtils::ContainsUpperCase("abc")); | 183 EXPECT_FALSE(QuicTextUtils::ContainsUpperCase("abc")); |
186 EXPECT_FALSE(QuicTextUtils::ContainsUpperCase("")); | 184 EXPECT_FALSE(QuicTextUtils::ContainsUpperCase("")); |
187 EXPECT_FALSE(QuicTextUtils::ContainsUpperCase("123")); | 185 EXPECT_FALSE(QuicTextUtils::ContainsUpperCase("123")); |
188 EXPECT_TRUE(QuicTextUtils::ContainsUpperCase("ABC")); | 186 EXPECT_TRUE(QuicTextUtils::ContainsUpperCase("ABC")); |
189 EXPECT_TRUE(QuicTextUtils::ContainsUpperCase("aBc")); | 187 EXPECT_TRUE(QuicTextUtils::ContainsUpperCase("aBc")); |
190 } | 188 } |
191 | 189 |
192 TEST(QuicTextUtilsText, Split) { | 190 TEST(QuicTextUtilsText, Split) { |
193 EXPECT_EQ(std::vector<StringPiece>({"a", "b", "c"}), | 191 EXPECT_EQ(std::vector<QuicStringPiece>({"a", "b", "c"}), |
194 QuicTextUtils::Split("a,b,c", ',')); | 192 QuicTextUtils::Split("a,b,c", ',')); |
195 EXPECT_EQ(std::vector<StringPiece>({"a", "b", "c"}), | 193 EXPECT_EQ(std::vector<QuicStringPiece>({"a", "b", "c"}), |
196 QuicTextUtils::Split("a:b:c", ':')); | 194 QuicTextUtils::Split("a:b:c", ':')); |
197 EXPECT_EQ(std::vector<StringPiece>({"a:b:c"}), | 195 EXPECT_EQ(std::vector<QuicStringPiece>({"a:b:c"}), |
198 QuicTextUtils::Split("a:b:c", ',')); | 196 QuicTextUtils::Split("a:b:c", ',')); |
199 } | 197 } |
200 | 198 |
201 } // namespace test | 199 } // namespace test |
202 } // namespace net | 200 } // namespace net |
OLD | NEW |