OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 {L" a \r b\n c \r\n d \t\re \t f \n ", true, L"abcde f"}, | 150 {L" a \r b\n c \r\n d \t\re \t f \n ", true, L"abcde f"}, |
151 }; | 151 }; |
152 | 152 |
153 TEST(StringUtilTest, CollapseWhitespace) { | 153 TEST(StringUtilTest, CollapseWhitespace) { |
154 for (size_t i = 0; i < arraysize(collapse_cases); ++i) { | 154 for (size_t i = 0; i < arraysize(collapse_cases); ++i) { |
155 const collapse_case& value = collapse_cases[i]; | 155 const collapse_case& value = collapse_cases[i]; |
156 EXPECT_EQ(value.output, CollapseWhitespace(value.input, value.trim)); | 156 EXPECT_EQ(value.output, CollapseWhitespace(value.input, value.trim)); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
| 160 static const struct collapse_case_ascii { |
| 161 const char* input; |
| 162 const bool trim; |
| 163 const char* output; |
| 164 } collapse_cases_ascii[] = { |
| 165 {" Google Video ", false, "Google Video"}, |
| 166 {"Google Video", false, "Google Video"}, |
| 167 {"", false, ""}, |
| 168 {" ", false, ""}, |
| 169 {"\t\rTest String\n", false, "Test String"}, |
| 170 {" Test \n \t String ", false, "Test String"}, |
| 171 {" Test String", false, "Test String"}, |
| 172 {"Test String ", false, "Test String"}, |
| 173 {"Test String", false, "Test String"}, |
| 174 {"", true, ""}, |
| 175 {"\n", true, ""}, |
| 176 {" \r ", true, ""}, |
| 177 {"\nFoo", true, "Foo"}, |
| 178 {"\r Foo ", true, "Foo"}, |
| 179 {" Foo bar ", true, "Foo bar"}, |
| 180 {" \tFoo bar \n", true, "Foo bar"}, |
| 181 {" a \r b\n c \r\n d \t\re \t f \n ", true, "abcde f"}, |
| 182 }; |
| 183 |
| 184 TEST(StringUtilTest, CollapseWhitespaceASCII) { |
| 185 for (size_t i = 0; i < arraysize(collapse_cases_ascii); ++i) { |
| 186 const collapse_case_ascii& value = collapse_cases_ascii[i]; |
| 187 EXPECT_EQ(value.output, CollapseWhitespaceASCII(value.input, value.trim)); |
| 188 } |
| 189 } |
160 | 190 |
161 TEST(StringUtilTest, IsStringUTF8) { | 191 TEST(StringUtilTest, IsStringUTF8) { |
162 EXPECT_TRUE(IsStringUTF8("abc")); | 192 EXPECT_TRUE(IsStringUTF8("abc")); |
163 EXPECT_TRUE(IsStringUTF8("\xc2\x81")); | 193 EXPECT_TRUE(IsStringUTF8("\xc2\x81")); |
164 EXPECT_TRUE(IsStringUTF8("\xe1\x80\xbf")); | 194 EXPECT_TRUE(IsStringUTF8("\xe1\x80\xbf")); |
165 EXPECT_TRUE(IsStringUTF8("\xf1\x80\xa0\xbf")); | 195 EXPECT_TRUE(IsStringUTF8("\xf1\x80\xa0\xbf")); |
166 EXPECT_TRUE(IsStringUTF8("a\xc2\x81\xe1\x80\xbf\xf1\x80\xa0\xbf")); | 196 EXPECT_TRUE(IsStringUTF8("a\xc2\x81\xe1\x80\xbf\xf1\x80\xa0\xbf")); |
167 EXPECT_TRUE(IsStringUTF8("\xef\xbb\xbf" "abc")); // UTF-8 BOM | 197 EXPECT_TRUE(IsStringUTF8("\xef\xbb\xbf" "abc")); // UTF-8 BOM |
168 | 198 |
169 // surrogate code points | 199 // surrogate code points |
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 } | 1677 } |
1648 } | 1678 } |
1649 | 1679 |
1650 TEST(StringUtilTest, HexEncode) { | 1680 TEST(StringUtilTest, HexEncode) { |
1651 std::string hex(HexEncode(NULL, 0)); | 1681 std::string hex(HexEncode(NULL, 0)); |
1652 EXPECT_EQ(hex.length(), 0U); | 1682 EXPECT_EQ(hex.length(), 0U); |
1653 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 1683 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
1654 hex = HexEncode(bytes, sizeof(bytes)); | 1684 hex = HexEncode(bytes, sizeof(bytes)); |
1655 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 1685 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
1656 } | 1686 } |
OLD | NEW |