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

Unified Diff: tests/corelib/regexp/toString_test.dart

Issue 667043003: Port regexp tests from V8 to Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
Index: tests/corelib/regexp/toString_test.dart
diff --git a/tests/corelib/regexp/toString_test.dart b/tests/corelib/regexp/toString_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ba041ce1fa87006800741de5f00351e5dc4b7b90
--- /dev/null
+++ b/tests/corelib/regexp/toString_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'util.dart';
+import 'package:expect/expect.dart';
+
+void main() {
+ dynamic testForwardSlash(pattern, _string)
+ {
+ var string = _string;
+
+ var re1 = new RegExp(pattern);
+
+ return re1.hasMatch(string);
+ }
+
+ dynamic testLineTerminator(pattern)
+ {
+ var re1 = new RegExp(pattern);
+
+ return new RegExp(r"\n|\r|\u2028|\u2029").hasMatch(re1.toString());
+ }
+
+ // These strings are equivalent, since the '\' is identity escaping the '/' at the string level.
+ shouldBeTrue(testForwardSlash("^/\$", "/"));
+ shouldBeTrue(testForwardSlash("^\/\$", "/"));
+ // This string passes "^\/$" to the RegExp, so the '/' is escaped in the re!
+ shouldBeTrue(testForwardSlash("^\\/\$", "/"));
+ // These strings pass "^\\/$" and "^\\\/$" respectively to the RegExp, giving one '\' to match.
+ shouldBeTrue(testForwardSlash("^\\\\/\$", "\\/"));
+ shouldBeTrue(testForwardSlash("^\\\\\\/\$", "\\/"));
+ // These strings match two backslashes (the second with the '/' escaped).
+ shouldBeTrue(testForwardSlash("^\\\\\\\\/\$", "\\\\/"));
+ shouldBeTrue(testForwardSlash("^\\\\\\\\\\/\$", "\\\\/"));
+ // Test that nothing goes wrongif there are multiple forward slashes!
+ shouldBeTrue(testForwardSlash("x/x/x", "x/x/x"));
+ shouldBeTrue(testForwardSlash("x\\/x/x", "x/x/x"));
+ shouldBeTrue(testForwardSlash("x/x\\/x", "x/x/x"));
+ shouldBeTrue(testForwardSlash("x\\/x\\/x", "x/x/x"));
+
+ shouldBeFalse(testLineTerminator("\\n"));
+ shouldBeFalse(testLineTerminator("\\\\n"));
+ shouldBeFalse(testLineTerminator("\\r"));
+ shouldBeFalse(testLineTerminator("\\\\r"));
+ shouldBeFalse(testLineTerminator("\\u2028"));
+ shouldBeFalse(testLineTerminator("\\\\u2028"));
+ shouldBeFalse(testLineTerminator("\\u2029"));
+ shouldBeFalse(testLineTerminator("\\\\u2029"));
+}

Powered by Google App Engine
This is Rietveld 408576698