Chromium Code Reviews| Index: test/cctest/test-strings.cc |
| diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc |
| index 4d9b264e93f4099f28be3142fcd820fba365a10f..1cfdcd2003cce32d94f0ec0d0bfb7ad8116cc69e 100644 |
| --- a/test/cctest/test-strings.cc |
| +++ b/test/cctest/test-strings.cc |
| @@ -481,3 +481,55 @@ TEST(CachedHashOverflow) { |
| } |
| } |
| } |
| + |
| + |
| +TEST(TruncateSlice) { |
| + printf("Truncate Sliced String\n"); |
| + FLAG_string_slices = true; |
| + InitializeVM(); |
| + v8::HandleScope scope; |
| + Handle<String> string = |
| + FACTORY->NewStringFromAscii(CStrVector("parentparentparent")); |
| + Handle<String> parent = FACTORY->NewConsString(string, string); |
| + CHECK(parent->IsConsString()); |
| + CHECK(!parent->IsFlat()); |
| + Handle<String> slice = FACTORY->NewSubString(parent, 1, 25); |
| + CHECK(parent->IsFlat()); // After slicing, parent becomes flat. |
| + CHECK(slice->IsSlicedString()); |
| + CHECK(!slice->IsTruncated()); |
| + CHECK(!slice->IsFlatAndTruncated()); |
| + CHECK(slice->IsFlat()); |
| + TruncateString(slice); |
| + CHECK(slice->IsTruncated()); |
| + CHECK(slice->IsFlatAndTruncated()); |
| +} |
| + |
| + |
| +TEST(TrivialSlice) { |
| + // This tests whether a slice that contains the entire parent string |
| + // actually creates a new string (it should not). |
| + FLAG_string_slices = true; |
| + InitializeVM(); |
| + HandleScope scope; |
| + v8::Local<v8::Value> result; |
| + Handle<String> string; |
| + const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
| + const char* check = "str.slice(0,26)"; |
| + const char* crosscheck = "str.slice(1,25)"; |
| + |
| + v8::Script::Compile(v8::String::New(init))->Run(); |
| + |
| + result = v8::Script::Compile(v8::String::New(check))->Run(); |
|
antonm
2011/08/04 12:18:48
I think we have something like CompileAndRun
|
| + CHECK(result->IsString()); |
| + string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| + CHECK(!string->IsSlicedString()); |
| + |
| + string = FACTORY->NewSubString(string, 0, 26); |
| + CHECK(!string->IsSlicedString()); |
| + |
| + result = v8::Script::Compile(v8::String::New(crosscheck))->Run(); |
| + CHECK(result->IsString()); |
| + string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| + CHECK(string->IsSlicedString()); |
| + CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
| +} |