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

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

Issue 3585010: API: expose RegExp. (Closed)
Patch Set: Created 10 years, 2 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
« src/api.cc ('K') | « src/api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index f1a6eada40e8619d92bdb255ce5f8f9f261fc62a..3b96c916457dc36abcfff399bfce6e1567104285 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -11619,3 +11619,58 @@ TEST(GlobalLoadICGC) {
CheckSurvivingGlobalObjectsCount(1);
}
}
+
+
+TEST(RegExp) {
+ v8::HandleScope scope;
+ LocalContext context;
+
+ v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone);
antonm 2010/10/04 14:44:55 maybe add a test case that checks that regexps cre
Vitaly Repeshko 2010/10/04 15:04:42 Done.
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("foo")));
+ CHECK_EQ(re->GetFlags(), v8::RegExp::kNone);
+
+ re = v8::RegExp::New(v8_str("bar"),
+ static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
+ v8::RegExp::kGlobal));
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("bar")));
+ CHECK_EQ(static_cast<int>(re->GetFlags()),
+ v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal);
+
+ re = v8::RegExp::New(v8_str("baz"),
+ static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
+ v8::RegExp::kMultiline));
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("baz")));
+ CHECK_EQ(static_cast<int>(re->GetFlags()),
+ v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline);
+
+ re = CompileRun("/quux/").As<v8::RegExp>();
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("quux")));
+ CHECK_EQ(re->GetFlags(), v8::RegExp::kNone);
+
+ re = CompileRun("/quux/gm").As<v8::RegExp>();
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("quux")));
+ CHECK_EQ(static_cast<int>(re->GetFlags()),
+ v8::RegExp::kGlobal | v8::RegExp::kMultiline);
+
+ // Override the RegExp constructor and check the API constructor
+ // still works.
+ CompileRun("RegExp = function() {}");
+
+ re = v8::RegExp::New(v8_str("foobar"), v8::RegExp::kNone);
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("foobar")));
+ CHECK_EQ(re->GetFlags(), v8::RegExp::kNone);
+
+ re = v8::RegExp::New(v8_str("foobarbaz"),
+ static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
+ v8::RegExp::kMultiline));
+ CHECK(re->IsRegExp());
+ CHECK(re->GetSource()->Equals(v8_str("foobarbaz")));
+ CHECK_EQ(static_cast<int>(re->GetFlags()),
+ v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline);
+}
« src/api.cc ('K') | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698