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

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

Issue 1280473002: Update ToLower/UpperASCII API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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') | chrome/browser/chromeos/input_method/input_method_util.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 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 std::string string_with_nul(chars_with_nul, length_with_nul); 496 std::string string_with_nul(chars_with_nul, length_with_nul);
497 string16 string16_with_nul = ASCIIToUTF16(string_with_nul); 497 string16 string16_with_nul = ASCIIToUTF16(string_with_nul);
498 EXPECT_EQ(static_cast<string16::size_type>(length_with_nul), 498 EXPECT_EQ(static_cast<string16::size_type>(length_with_nul),
499 string16_with_nul.length()); 499 string16_with_nul.length());
500 std::string narrow_with_nul = UTF16ToASCII(string16_with_nul); 500 std::string narrow_with_nul = UTF16ToASCII(string16_with_nul);
501 EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul), 501 EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul),
502 narrow_with_nul.length()); 502 narrow_with_nul.length());
503 EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul)); 503 EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul));
504 } 504 }
505 505
506 TEST(StringUtilTest, ToLowerASCII) {
507 EXPECT_EQ('c', ToLowerASCII('C'));
508 EXPECT_EQ('c', ToLowerASCII('c'));
509 EXPECT_EQ('2', ToLowerASCII('2'));
510
511 EXPECT_EQ(static_cast<char16>('c'), ToLowerASCII(static_cast<char16>('C')));
512 EXPECT_EQ(static_cast<char16>('c'), ToLowerASCII(static_cast<char16>('c')));
513 EXPECT_EQ(static_cast<char16>('2'), ToLowerASCII(static_cast<char16>('2')));
514
515 EXPECT_EQ("cc2", ToLowerASCII("Cc2"));
516 EXPECT_EQ(ASCIIToUTF16("cc2"), ToLowerASCII(ASCIIToUTF16("Cc2")));
517 }
518
506 TEST(StringUtilTest, ToUpperASCII) { 519 TEST(StringUtilTest, ToUpperASCII) {
507 EXPECT_EQ('C', ToUpperASCII('C')); 520 EXPECT_EQ('C', ToUpperASCII('C'));
508 EXPECT_EQ('C', ToUpperASCII('c')); 521 EXPECT_EQ('C', ToUpperASCII('c'));
509 EXPECT_EQ('2', ToUpperASCII('2')); 522 EXPECT_EQ('2', ToUpperASCII('2'));
510 523
511 EXPECT_EQ(L'C', ToUpperASCII(L'C')); 524 EXPECT_EQ(static_cast<char16>('C'), ToUpperASCII(static_cast<char16>('C')));
512 EXPECT_EQ(L'C', ToUpperASCII(L'c')); 525 EXPECT_EQ(static_cast<char16>('C'), ToUpperASCII(static_cast<char16>('c')));
513 EXPECT_EQ(L'2', ToUpperASCII(L'2')); 526 EXPECT_EQ(static_cast<char16>('2'), ToUpperASCII(static_cast<char16>('2')));
514 527
515 std::string in_place_a("Cc2"); 528 EXPECT_EQ("CC2", ToUpperASCII("Cc2"));
516 StringToUpperASCII(&in_place_a); 529 EXPECT_EQ(ASCIIToUTF16("CC2"), ToUpperASCII(ASCIIToUTF16("Cc2")));
517 EXPECT_EQ("CC2", in_place_a);
518
519 std::wstring in_place_w(L"Cc2");
520 StringToUpperASCII(&in_place_w);
521 EXPECT_EQ(L"CC2", in_place_w);
522
523 std::string original_a("Cc2");
524 std::string upper_a = StringToUpperASCII(original_a);
525 EXPECT_EQ("CC2", upper_a);
526
527 std::wstring original_w(L"Cc2");
528 std::wstring upper_w = StringToUpperASCII(original_w);
529 EXPECT_EQ(L"CC2", upper_w);
530 } 530 }
531 531
532 TEST(StringUtilTest, LowerCaseEqualsASCII) { 532 TEST(StringUtilTest, LowerCaseEqualsASCII) {
533 static const struct { 533 static const struct {
534 const char* src_a; 534 const char* src_a;
535 const char* dst; 535 const char* dst;
536 } lowercase_cases[] = { 536 } lowercase_cases[] = {
537 { "FoO", "foo" }, 537 { "FoO", "foo" },
538 { "foo", "foo" }, 538 { "foo", "foo" },
539 { "FOO", "foo" }, 539 { "FOO", "foo" },
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 const std::string live = kLive; 1109 const std::string live = kLive;
1110 std::string dead = live; 1110 std::string dead = live;
1111 strncpy(WriteInto(&dead, 5), kDead, 4); 1111 strncpy(WriteInto(&dead, 5), kDead, 4);
1112 EXPECT_EQ(kDead, dead); 1112 EXPECT_EQ(kDead, dead);
1113 EXPECT_EQ(4u, dead.size()); 1113 EXPECT_EQ(4u, dead.size());
1114 EXPECT_EQ(kLive, live); 1114 EXPECT_EQ(kLive, live);
1115 EXPECT_EQ(4u, live.size()); 1115 EXPECT_EQ(4u, live.size());
1116 } 1116 }
1117 1117
1118 } // namespace base 1118 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_util.cc ('k') | chrome/browser/chromeos/input_method/input_method_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698