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

Side by Side Diff: test/cctest/test-strings.cc

Issue 1512028: Landing http://codereview.chromium.org/1594017 for Ryan. (Closed)
Patch Set: Created 10 years, 8 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 | « src/api.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 // Check that we can traverse very deep stacks of ConsStrings using 3 // Check that we can traverse very deep stacks of ConsStrings using
4 // StringInputBuffer. Check that Get(int) works on very deep stacks 4 // StringInputBuffer. Check that Get(int) works on very deep stacks
5 // of ConsStrings. These operations may not be very fast, but they 5 // of ConsStrings. These operations may not be very fast, but they
6 // should be possible without getting errors due to too deep recursion. 6 // should be possible without getting errors due to too deep recursion.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "v8.h" 10 #include "v8.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Check that the contents are correct 340 // Check that the contents are correct
341 for (int j = 0; j < lengths[i]; j++) 341 for (int j = 0; j < lengths[i]; j++)
342 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); 342 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j]));
343 // Check that the rest of the buffer hasn't been touched 343 // Check that the rest of the buffer hasn't been touched
344 for (int j = lengths[i]; j < 11; j++) 344 for (int j = lengths[i]; j < 11; j++)
345 CHECK_EQ(kNoChar, buffer[j]); 345 CHECK_EQ(kNoChar, buffer[j]);
346 } 346 }
347 } 347 }
348 348
349 349
350 TEST(StringConcatFlatten) {
351 InitializeVM();
352 v8::HandleScope handle_scope;
353
354 const char* stringA = "0123456789";
355 const char* stringB = "ABCDEFGHIJ";
356
357 v8::Local<v8::String> a = v8::String::New(stringA);
358 v8::Local<v8::String> b = v8::String::New(stringB);
359
360 v8::Local<v8::String> cons = v8::String::Concat(a, b);
361
362 i::Handle<i::String> str = v8::Utils::OpenHandle(*cons);
363 CHECK(!str->IsFlat());
364
365 cons->Flatten();
366
367 CHECK(str->IsFlat());
368
369 char buffer[21];
370 cons->WriteUtf8(buffer);
371
372 for (int i = 0; i < 10; i++) {
373 CHECK_EQ(stringA[i], buffer[i]);
374 }
375
376 for (int i = 0; i < 10; i++) {
377 CHECK_EQ(stringB[i], buffer[i + 10]);
378 }
379 }
380
381
350 TEST(ExternalShortStringAdd) { 382 TEST(ExternalShortStringAdd) {
351 ZoneScope zone(DELETE_ON_EXIT); 383 ZoneScope zone(DELETE_ON_EXIT);
352 384
353 InitializeVM(); 385 InitializeVM();
354 v8::HandleScope handle_scope; 386 v8::HandleScope handle_scope;
355 387
356 // Make sure we cover all always-flat lengths and at least one above. 388 // Make sure we cover all always-flat lengths and at least one above.
357 static const int kMaxLength = 20; 389 static const int kMaxLength = 20;
358 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength); 390 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength);
359 391
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 " if (non_ascii[i] !=" 458 " if (non_ascii[i] !="
427 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" 459 " (non_ascii[j] + external_non_ascii[i - j])) return 12;"
428 " }" 460 " }"
429 " }" 461 " }"
430 " return 0;" 462 " return 0;"
431 "};" 463 "};"
432 "test()"; 464 "test()";
433 CHECK_EQ(0, 465 CHECK_EQ(0,
434 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value()); 466 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value());
435 } 467 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698