| Index: test/cctest/test-strings.cc
|
| diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
|
| index 4d9b264e93f4099f28be3142fcd820fba365a10f..d539a5f241d97400c30583f67ba02bd4bc1d0ce8 100644
|
| --- a/test/cctest/test-strings.cc
|
| +++ b/test/cctest/test-strings.cc
|
| @@ -481,3 +481,59 @@ TEST(CachedHashOverflow) {
|
| }
|
| }
|
| }
|
| +
|
| +
|
| +TEST(TruncateSlice) {
|
| + 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);
|
| + // After slicing, the original string becomes a flat cons.
|
| + CHECK(parent->IsFlat());
|
| + CHECK(slice->IsSlicedString());
|
| + CHECK_EQ(SlicedString::cast(*slice)->parent(),
|
| + ConsString::cast(*parent)->first());
|
| + CHECK(SlicedString::cast(*slice)->parent()->IsSeqString());
|
| + CHECK(!slice->IsTruncated());
|
| + CHECK(!slice->IsFlatAndTruncated());
|
| + CHECK(slice->IsFlat());
|
| + TruncateString(slice);
|
| + CHECK(slice->IsTruncated());
|
| + CHECK(slice->IsFlatAndTruncated());
|
| + CHECK_NE(slice->GetIndirect(), parent->GetIndirect());
|
| +}
|
| +
|
| +
|
| +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();
|
| + 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()));
|
| +}
|
|
|