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

Side by Side Diff: base/strings/string_util_unittest.cc

Issue 1399253004: Make base::IsUnicodeWhitespace('\0') return false. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add BASE_EXPORT Created 5 years, 2 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/strings/string_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/strings/string_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698