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

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 non-ASCII codepoint tests 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 EXPECT_FALSE(IsUnicodeWhitespace(L'\x4100'));
1091
1092 // Actual unicode whitespace.
1093 EXPECT_TRUE(IsUnicodeWhitespace(L' '));
1094 EXPECT_TRUE(IsUnicodeWhitespace(L'\xa0'));
1095 EXPECT_TRUE(IsUnicodeWhitespace(L'\x3000'));
1096 EXPECT_TRUE(IsUnicodeWhitespace(L'\t'));
1097 EXPECT_TRUE(IsUnicodeWhitespace(L'\r'));
1098 EXPECT_TRUE(IsUnicodeWhitespace(L'\v'));
1099 EXPECT_TRUE(IsUnicodeWhitespace(L'\f'));
1100 EXPECT_TRUE(IsUnicodeWhitespace(L'\n'));
1101 }
1102
1083 class WriteIntoTest : public testing::Test { 1103 class WriteIntoTest : public testing::Test {
1084 protected: 1104 protected:
1085 static void WritesCorrectly(size_t num_chars) { 1105 static void WritesCorrectly(size_t num_chars) {
1086 std::string buffer; 1106 std::string buffer;
1087 char kOriginal[] = "supercali"; 1107 char kOriginal[] = "supercali";
1088 strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars); 1108 strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars);
1089 // Using std::string(buffer.c_str()) instead of |buffer| truncates the 1109 // Using std::string(buffer.c_str()) instead of |buffer| truncates the
1090 // string at the first \0. 1110 // string at the first \0.
1091 EXPECT_EQ(std::string(kOriginal, 1111 EXPECT_EQ(std::string(kOriginal,
1092 std::min(num_chars, arraysize(kOriginal) - 1)), 1112 std::min(num_chars, arraysize(kOriginal) - 1)),
(...skipping 16 matching lines...) Expand all
1109 const std::string live = kLive; 1129 const std::string live = kLive;
1110 std::string dead = live; 1130 std::string dead = live;
1111 strncpy(WriteInto(&dead, 5), kDead, 4); 1131 strncpy(WriteInto(&dead, 5), kDead, 4);
1112 EXPECT_EQ(kDead, dead); 1132 EXPECT_EQ(kDead, dead);
1113 EXPECT_EQ(4u, dead.size()); 1133 EXPECT_EQ(4u, dead.size());
1114 EXPECT_EQ(kLive, live); 1134 EXPECT_EQ(kLive, live);
1115 EXPECT_EQ(4u, live.size()); 1135 EXPECT_EQ(4u, live.size());
1116 } 1136 }
1117 1137
1118 } // namespace base 1138 } // 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