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

Side by Side Diff: base/string_util_unittest.cc

Issue 18603: Add a replace_all param to ReplaceSubstringsAfterOffset and update call sites. (Closed)
Patch Set: Add ReplaceFirstSubstringAfterPos() Created 11 years, 11 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/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 (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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 }; 668 };
669 669
670 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 670 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
671 std::wstring str(cases[i].str); 671 std::wstring str(cases[i].str);
672 ReplaceSubstringsAfterOffset(&str, cases[i].start_offset, 672 ReplaceSubstringsAfterOffset(&str, cases[i].start_offset,
673 cases[i].find_this, cases[i].replace_with); 673 cases[i].find_this, cases[i].replace_with);
674 EXPECT_EQ(cases[i].expected, str); 674 EXPECT_EQ(cases[i].expected, str);
675 } 675 }
676 } 676 }
677 677
678 TEST(StringUtilTest, ReplaceFirstSubstringAfterOffset) {
679 static const struct {
680 const wchar_t* str;
681 std::wstring::size_type start_offset;
682 const wchar_t* find_this;
683 const wchar_t* replace_with;
684 const wchar_t* expected;
685 } cases[] = {
686 {L"aaa", 0, L"a", L"b", L"baa"},
687 {L"abb", 0, L"ab", L"a", L"ab"},
688 {L"Removing some substrings inging", 0, L"ing", L"",
689 L"Remov some substrings inging"},
690 {L"Not found", 0, L"x", L"0", L"Not found"},
691 {L"Not found again", 5, L"x", L"0", L"Not found again"},
692 {L" Making it much longer ", 0, L" ", L"Four score and seven years ago",
693 L"Four score and seven years agoMaking it much longer "},
694 {L"Invalid offset", 9999, L"t", L"foobar", L"Invalid offset"},
695 {L"Replace me only me once", 4, L"me ", L"", L"Replace only me once"},
696 {L"abababab", 2, L"ab", L"c", L"abcabab"},
697 };
698
699 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
700 std::wstring str(cases[i].str);
701 ReplaceFirstSubstringAfterOffset(&str, cases[i].start_offset,
702 cases[i].find_this, cases[i].replace_with);
703 EXPECT_EQ(cases[i].expected, str);
704 }
705 }
706
678 namespace { 707 namespace {
679 708
680 template <typename INT> 709 template <typename INT>
681 struct IntToStringTest { 710 struct IntToStringTest {
682 INT num; 711 INT num;
683 const char* sexpected; 712 const char* sexpected;
684 const char* uexpected; 713 const char* uexpected;
685 }; 714 };
686 715
687 } 716 }
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" }, 1444 { L"Hello, my name is Tom", 10, true, L"Hell...Tom" },
1416 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" } 1445 { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" }
1417 }; 1446 };
1418 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 1447 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1419 std::wstring output; 1448 std::wstring output;
1420 EXPECT_EQ(cases[i].result, 1449 EXPECT_EQ(cases[i].result,
1421 ElideString(cases[i].input, cases[i].max_len, &output)); 1450 ElideString(cases[i].input, cases[i].max_len, &output));
1422 EXPECT_TRUE(output == cases[i].output); 1451 EXPECT_TRUE(output == cases[i].output);
1423 } 1452 }
1424 } 1453 }
OLDNEW
« no previous file with comments | « base/string_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698