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

Side by Side Diff: base/string_util_unittest.cc

Issue 6017001: Move ElideString() from base/string_util.cc to app/text_elider.cc to ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « base/string_util.cc ('k') | chrome/browser/chromeos/external_protocol_dialog.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 { L"%f %d %o %u", true }, 1049 { L"%f %d %o %u", true },
1050 { L"%-8d (%02.1f%)", true }, 1050 { L"%-8d (%02.1f%)", true },
1051 { L"% 10s", false }, 1051 { L"% 10s", false },
1052 { L"% 10ls", true } 1052 { L"% 10ls", true }
1053 }; 1053 };
1054 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 1054 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1055 EXPECT_EQ(cases[i].portable, base::IsWprintfFormatPortable(cases[i].input)); 1055 EXPECT_EQ(cases[i].portable, base::IsWprintfFormatPortable(cases[i].input));
1056 } 1056 }
1057 } 1057 }
1058 1058
1059 TEST(StringUtilTest, ElideString) {
1060 struct TestData {
1061 const wchar_t* input;
1062 int max_len;
1063 bool result;
1064 const wchar_t* output;
1065 } cases[] = {
1066 { L"Hello", 0, true, L"" },
1067 { L"", 0, false, L"" },
1068 { L"Hello, my name is Tom", 1, true, L"H" },
1069 { L"Hello, my name is Tom", 2, true, L"He" },
1070 { L"Hello, my name is Tom", 3, true, L"H.m" },
1071 { L"Hello, my name is Tom", 4, true, L"H..m" },
1072 { L"Hello, my name is Tom", 5, true, L"H...m" },
1073 { L"Hello, my name is Tom", 6, true, L"He...m" },
1074 { L"Hello, my name is Tom", 7, true, L"He...om" },
1075 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" },
1076 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" }
1077 };
1078 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1079 std::wstring output;
1080 EXPECT_EQ(cases[i].result,
1081 ElideString(cases[i].input, cases[i].max_len, &output));
1082 EXPECT_TRUE(output == cases[i].output);
1083 }
1084 }
1085
1086 TEST(StringUtilTest, RemoveChars) { 1059 TEST(StringUtilTest, RemoveChars) {
1087 const char* kRemoveChars = "-/+*"; 1060 const char* kRemoveChars = "-/+*";
1088 std::string input = "A-+bc/d!*"; 1061 std::string input = "A-+bc/d!*";
1089 EXPECT_TRUE(RemoveChars(input, kRemoveChars, &input)); 1062 EXPECT_TRUE(RemoveChars(input, kRemoveChars, &input));
1090 EXPECT_EQ("Abcd!", input); 1063 EXPECT_EQ("Abcd!", input);
1091 1064
1092 // No characters match kRemoveChars. 1065 // No characters match kRemoveChars.
1093 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input)); 1066 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input));
1094 EXPECT_EQ("Abcd!", input); 1067 EXPECT_EQ("Abcd!", input);
1095 1068
(...skipping 10 matching lines...) Expand all
1106 EXPECT_FALSE(ContainsOnlyChars("Hello", "")); 1079 EXPECT_FALSE(ContainsOnlyChars("Hello", ""));
1107 1080
1108 EXPECT_TRUE(ContainsOnlyChars("", "1234")); 1081 EXPECT_TRUE(ContainsOnlyChars("", "1234"));
1109 EXPECT_TRUE(ContainsOnlyChars("1", "1234")); 1082 EXPECT_TRUE(ContainsOnlyChars("1", "1234"));
1110 EXPECT_TRUE(ContainsOnlyChars("1", "4321")); 1083 EXPECT_TRUE(ContainsOnlyChars("1", "4321"));
1111 EXPECT_TRUE(ContainsOnlyChars("123", "4321")); 1084 EXPECT_TRUE(ContainsOnlyChars("123", "4321"));
1112 EXPECT_FALSE(ContainsOnlyChars("123a", "4321")); 1085 EXPECT_FALSE(ContainsOnlyChars("123a", "4321"));
1113 } 1086 }
1114 1087
1115 } // namespace base 1088 } // namespace base
OLDNEW
« no previous file with comments | « base/string_util.cc ('k') | chrome/browser/chromeos/external_protocol_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698