OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 EXPECT_EQ(1, CompareCaseInsensitiveASCII("Asdfb", "aSDfA")); | 1073 EXPECT_EQ(1, CompareCaseInsensitiveASCII("Asdfb", "aSDfA")); |
1074 } | 1074 } |
1075 | 1075 |
1076 TEST(StringUtilTest, EqualsCaseInsensitiveASCII) { | 1076 TEST(StringUtilTest, EqualsCaseInsensitiveASCII) { |
1077 EXPECT_TRUE(EqualsCaseInsensitiveASCII("", "")); | 1077 EXPECT_TRUE(EqualsCaseInsensitiveASCII("", "")); |
1078 EXPECT_TRUE(EqualsCaseInsensitiveASCII("Asdf", "aSDF")); | 1078 EXPECT_TRUE(EqualsCaseInsensitiveASCII("Asdf", "aSDF")); |
1079 EXPECT_FALSE(EqualsCaseInsensitiveASCII("bsdf", "aSDF")); | 1079 EXPECT_FALSE(EqualsCaseInsensitiveASCII("bsdf", "aSDF")); |
1080 EXPECT_FALSE(EqualsCaseInsensitiveASCII("Asdf", "aSDFz")); | 1080 EXPECT_FALSE(EqualsCaseInsensitiveASCII("Asdf", "aSDFz")); |
1081 } | 1081 } |
1082 | 1082 |
1083 TEST(StringUtilTest, IsUnicodeWhitespace) { | |
1084 // NOT unicode white space. | |
1085 EXPECT_FALSE(IsUnicodeWhitespace(L'\0')); | |
1086 EXPECT_FALSE(IsUnicodeWhitespace(L'A')); | |
1087 EXPECT_FALSE(IsUnicodeWhitespace(L'0')); | |
1088 EXPECT_FALSE(IsUnicodeWhitespace(L'.')); | |
1089 EXPECT_FALSE(IsUnicodeWhitespace(L';')); | |
1090 | |
1091 // Actual unicode whitespace. | |
1092 EXPECT_TRUE(IsUnicodeWhitespace(L' ')); | |
1093 EXPECT_TRUE(IsUnicodeWhitespace(L'\t')); | |
1094 EXPECT_TRUE(IsUnicodeWhitespace(L'\r')); | |
1095 EXPECT_TRUE(IsUnicodeWhitespace(L'\v')); | |
1096 EXPECT_TRUE(IsUnicodeWhitespace(L'\f')); | |
1097 EXPECT_TRUE(IsUnicodeWhitespace(L'\n')); | |
brettw
2015/10/13 21:41:51
Can you add a non-ASCII one as well, like:
0xA0 (
eroman
2015/10/13 22:04:22
Done. (Also added a non-ASCII non-whitespace test)
| |
1098 } | |
1099 | |
1083 class WriteIntoTest : public testing::Test { | 1100 class WriteIntoTest : public testing::Test { |
1084 protected: | 1101 protected: |
1085 static void WritesCorrectly(size_t num_chars) { | 1102 static void WritesCorrectly(size_t num_chars) { |
1086 std::string buffer; | 1103 std::string buffer; |
1087 char kOriginal[] = "supercali"; | 1104 char kOriginal[] = "supercali"; |
1088 strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars); | 1105 strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars); |
1089 // Using std::string(buffer.c_str()) instead of |buffer| truncates the | 1106 // Using std::string(buffer.c_str()) instead of |buffer| truncates the |
1090 // string at the first \0. | 1107 // string at the first \0. |
1091 EXPECT_EQ(std::string(kOriginal, | 1108 EXPECT_EQ(std::string(kOriginal, |
1092 std::min(num_chars, arraysize(kOriginal) - 1)), | 1109 std::min(num_chars, arraysize(kOriginal) - 1)), |
(...skipping 16 matching lines...) Expand all Loading... | |
1109 const std::string live = kLive; | 1126 const std::string live = kLive; |
1110 std::string dead = live; | 1127 std::string dead = live; |
1111 strncpy(WriteInto(&dead, 5), kDead, 4); | 1128 strncpy(WriteInto(&dead, 5), kDead, 4); |
1112 EXPECT_EQ(kDead, dead); | 1129 EXPECT_EQ(kDead, dead); |
1113 EXPECT_EQ(4u, dead.size()); | 1130 EXPECT_EQ(4u, dead.size()); |
1114 EXPECT_EQ(kLive, live); | 1131 EXPECT_EQ(kLive, live); |
1115 EXPECT_EQ(4u, live.size()); | 1132 EXPECT_EQ(4u, live.size()); |
1116 } | 1133 } |
1117 | 1134 |
1118 } // namespace base | 1135 } // namespace base |
OLD | NEW |