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

Unified Diff: test/cctest/test-strings.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Some more suggested changes. Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 4d9b264e93f4099f28be3142fcd820fba365a10f..17020a32542342344d5780bce911e3fd44f5725f 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -430,8 +430,7 @@ TEST(ExternalShortStringAdd) {
" return 0;"
"};"
"test()";
- CHECK_EQ(0,
- v8::Script::Compile(v8::String::New(source))->Run()->Int32Value());
+ CHECK_EQ(0, CompileRun(source)->Int32Value());
}
@@ -481,3 +480,52 @@ TEST(CachedHashOverflow) {
}
}
}
+
+
+TEST(SliceFromCons) {
+ 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->IsFlat());
+}
+
+
+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)";
+
+ CompileRun(init);
+
+ result = CompileRun(check);
+ CHECK(result->IsString());
+ string = v8::Utils::OpenHandle(v8::String::Cast(*result));
+ CHECK(!string->IsSlicedString());
+
+ string = FACTORY->NewSubString(string, 0, 26);
+ CHECK(!string->IsSlicedString());
+ result = CompileRun(crosscheck);
+ CHECK(result->IsString());
+ string = v8::Utils::OpenHandle(v8::String::Cast(*result));
+ CHECK(string->IsSlicedString());
+ CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
+}

Powered by Google App Engine
This is Rietveld 408576698