| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string16.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using ::testing::ElementsAre; | 18 using ::testing::ElementsAre; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 | 21 |
| 21 static const struct trim_case { | 22 static const struct trim_case { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 236 } |
| 236 | 237 |
| 237 // Test that TrimWhitespace() can take the same string for input and output | 238 // Test that TrimWhitespace() can take the same string for input and output |
| 238 output = ASCIIToUTF16(" This is a test \r\n"); | 239 output = ASCIIToUTF16(" This is a test \r\n"); |
| 239 EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output)); | 240 EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output)); |
| 240 EXPECT_EQ(ASCIIToUTF16("This is a test"), output); | 241 EXPECT_EQ(ASCIIToUTF16("This is a test"), output); |
| 241 | 242 |
| 242 // Once more, but with a string of whitespace | 243 // Once more, but with a string of whitespace |
| 243 output = ASCIIToUTF16(" \r\n"); | 244 output = ASCIIToUTF16(" \r\n"); |
| 244 EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output)); | 245 EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output)); |
| 245 EXPECT_EQ(ASCIIToUTF16(""), output); | 246 EXPECT_EQ(string16(), output); |
| 246 | 247 |
| 247 std::string output_ascii; | 248 std::string output_ascii; |
| 248 for (size_t i = 0; i < arraysize(trim_cases_ascii); ++i) { | 249 for (size_t i = 0; i < arraysize(trim_cases_ascii); ++i) { |
| 249 const trim_case_ascii& value = trim_cases_ascii[i]; | 250 const trim_case_ascii& value = trim_cases_ascii[i]; |
| 250 EXPECT_EQ(value.return_value, | 251 EXPECT_EQ(value.return_value, |
| 251 TrimWhitespace(value.input, value.positions, &output_ascii)); | 252 TrimWhitespace(value.input, value.positions, &output_ascii)); |
| 252 EXPECT_EQ(value.output, output_ascii); | 253 EXPECT_EQ(value.output, output_ascii); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 TEST(StringUtilTest, ContainsOnlyWhitespaceASCII) { | 321 TEST(StringUtilTest, ContainsOnlyWhitespaceASCII) { |
| 321 EXPECT_TRUE(ContainsOnlyWhitespaceASCII("")); | 322 EXPECT_TRUE(ContainsOnlyWhitespaceASCII("")); |
| 322 EXPECT_TRUE(ContainsOnlyWhitespaceASCII(" ")); | 323 EXPECT_TRUE(ContainsOnlyWhitespaceASCII(" ")); |
| 323 EXPECT_TRUE(ContainsOnlyWhitespaceASCII("\t")); | 324 EXPECT_TRUE(ContainsOnlyWhitespaceASCII("\t")); |
| 324 EXPECT_TRUE(ContainsOnlyWhitespaceASCII("\t \r \n ")); | 325 EXPECT_TRUE(ContainsOnlyWhitespaceASCII("\t \r \n ")); |
| 325 EXPECT_FALSE(ContainsOnlyWhitespaceASCII("a")); | 326 EXPECT_FALSE(ContainsOnlyWhitespaceASCII("a")); |
| 326 EXPECT_FALSE(ContainsOnlyWhitespaceASCII("\thello\r \n ")); | 327 EXPECT_FALSE(ContainsOnlyWhitespaceASCII("\thello\r \n ")); |
| 327 } | 328 } |
| 328 | 329 |
| 329 TEST(StringUtilTest, ContainsOnlyWhitespace) { | 330 TEST(StringUtilTest, ContainsOnlyWhitespace) { |
| 330 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16(""))); | 331 EXPECT_TRUE(ContainsOnlyWhitespace(string16())); |
| 331 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16(" "))); | 332 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16(" "))); |
| 332 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16("\t"))); | 333 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16("\t"))); |
| 333 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16("\t \r \n "))); | 334 EXPECT_TRUE(ContainsOnlyWhitespace(ASCIIToUTF16("\t \r \n "))); |
| 334 EXPECT_FALSE(ContainsOnlyWhitespace(ASCIIToUTF16("a"))); | 335 EXPECT_FALSE(ContainsOnlyWhitespace(ASCIIToUTF16("a"))); |
| 335 EXPECT_FALSE(ContainsOnlyWhitespace(ASCIIToUTF16("\thello\r \n "))); | 336 EXPECT_FALSE(ContainsOnlyWhitespace(ASCIIToUTF16("\thello\r \n "))); |
| 336 } | 337 } |
| 337 | 338 |
| 338 TEST(StringUtilTest, IsStringUTF8) { | 339 TEST(StringUtilTest, IsStringUTF8) { |
| 339 EXPECT_TRUE(IsStringUTF8("abc")); | 340 EXPECT_TRUE(IsStringUTF8("abc")); |
| 340 EXPECT_TRUE(IsStringUTF8("\xc2\x81")); | 341 EXPECT_TRUE(IsStringUTF8("\xc2\x81")); |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 const std::string live = kLive; | 1149 const std::string live = kLive; |
| 1149 std::string dead = live; | 1150 std::string dead = live; |
| 1150 strncpy(WriteInto(&dead, 5), kDead, 4); | 1151 strncpy(WriteInto(&dead, 5), kDead, 4); |
| 1151 EXPECT_STREQ(kDead, dead.c_str()); | 1152 EXPECT_STREQ(kDead, dead.c_str()); |
| 1152 EXPECT_EQ(4u, dead.size()); | 1153 EXPECT_EQ(4u, dead.size()); |
| 1153 EXPECT_STREQ(kLive, live.c_str()); | 1154 EXPECT_STREQ(kLive, live.c_str()); |
| 1154 EXPECT_EQ(4u, live.size()); | 1155 EXPECT_EQ(4u, live.size()); |
| 1155 } | 1156 } |
| 1156 | 1157 |
| 1157 } // namespace base | 1158 } // namespace base |
| OLD | NEW |