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

Side by Side Diff: third_party/WebKit/Source/platform/wtf/text/StringBuilderTest.cpp

Issue 2956603002: Add StringBuilder::erase(index) (Closed)
Patch Set: Removed last character optimization Created 3 years, 5 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 | « third_party/WebKit/Source/platform/wtf/text/StringBuilder.cpp ('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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ExpectBuilderContent("01234567", builder); 203 ExpectBuilderContent("01234567", builder);
204 204
205 builder.ToString(); 205 builder.ToString();
206 builder.Resize(7); 206 builder.Resize(7);
207 EXPECT_EQ(7U, builder.length()); 207 EXPECT_EQ(7U, builder.length());
208 ExpectBuilderContent("0123456", builder); 208 ExpectBuilderContent("0123456", builder);
209 builder.Resize(0); 209 builder.Resize(0);
210 ExpectEmpty(builder); 210 ExpectEmpty(builder);
211 } 211 }
212 212
213 TEST(StringBuilderTest, Erase) {
214 StringBuilder builder;
215 builder.Append(String("01234"));
216 // Erase from String.
217 builder.erase(3);
218 ExpectBuilderContent("0124", builder);
219 // Erase from buffer.
220 builder.erase(1);
221 ExpectBuilderContent("024", builder);
222 }
223
224 TEST(StringBuilderTest, Erase16) {
225 StringBuilder builder;
226 builder.Append(String(u"\uFF10\uFF11\uFF12\uFF13\uFF14"));
227 // Erase from String.
228 builder.erase(3);
229 ExpectBuilderContent(u"\uFF10\uFF11\uFF12\uFF14", builder);
230 // Erase from buffer.
231 builder.erase(1);
232 ExpectBuilderContent(u"\uFF10\uFF12\uFF14", builder);
233 }
234
235 TEST(StringBuilderTest, EraseLast) {
236 StringBuilder builder;
237 builder.Append("01234");
238 builder.erase(4);
239 ExpectBuilderContent("0123", builder);
240 }
241
213 TEST(StringBuilderTest, Equal) { 242 TEST(StringBuilderTest, Equal) {
214 StringBuilder builder1; 243 StringBuilder builder1;
215 StringBuilder builder2; 244 StringBuilder builder2;
216 EXPECT_TRUE(builder1 == builder2); 245 EXPECT_TRUE(builder1 == builder2);
217 EXPECT_TRUE(Equal(builder1, static_cast<LChar*>(0), 0)); 246 EXPECT_TRUE(Equal(builder1, static_cast<LChar*>(0), 0));
218 EXPECT_TRUE(builder1 == String()); 247 EXPECT_TRUE(builder1 == String());
219 EXPECT_TRUE(String() == builder1); 248 EXPECT_TRUE(String() == builder1);
220 EXPECT_TRUE(builder1 != String("abc")); 249 EXPECT_TRUE(builder1 != String("abc"));
221 250
222 builder1.Append("123"); 251 builder1.Append("123");
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 StringBuilder reference; 361 StringBuilder reference;
333 reference.Append(kReplacementCharacter); // Make it UTF-16. 362 reference.Append(kReplacementCharacter); // Make it UTF-16.
334 reference.Append(String::Number(kSomeNumber)); 363 reference.Append(String::Number(kSomeNumber));
335 StringBuilder test; 364 StringBuilder test;
336 test.Append(kReplacementCharacter); 365 test.Append(kReplacementCharacter);
337 test.AppendNumber(kSomeNumber); 366 test.AppendNumber(kSomeNumber);
338 EXPECT_EQ(reference, test); 367 EXPECT_EQ(reference, test);
339 } 368 }
340 369
341 } // namespace WTF 370 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/wtf/text/StringBuilder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698