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

Unified Diff: tests/corelib/regexp/util.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/util.dart
diff --git a/tests/corelib/regexp/util.dart b/tests/corelib/regexp/util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f7decbcb48bcd434caa39ad85015894214a416de
--- /dev/null
+++ b/tests/corelib/regexp/util.dart
@@ -0,0 +1,46 @@
+// 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.
+
+// Utility functions to easy porting of V8 tests.
+
Lasse Reichstein Nielsen 2014/10/23 13:21:58 Could you rename this to, e.g., "v8_regexp_helper.
zerny-google 2014/10/24 12:38:37 Done.
+import "package:expect/expect.dart";
+
+void assertEquals(actual, expected, [message]) =>
Lasse Reichstein Nielsen 2014/10/23 13:21:58 Please don't use => for void methods. Just { ... }
zerny-google 2014/10/24 12:38:37 Done.
+ Expect.equals(actual, expected, message);
+void assertTrue(actual, [message]) => Expect.isTrue(actual, message);
+void assertFalse(actual, [message]) => Expect.isFalse(actual, message);
+void assertThrows(fn, [testid]) => Expect.throws(fn);
Lasse Reichstein Nielsen 2014/10/23 13:21:57 => Expect.throws(fn, null, testid); Might as well
zerny-google 2014/10/24 12:38:37 Done.
+void assertNull(actual, [testid]) => Expect.isNull(actual);
Lasse Reichstein Nielsen 2014/10/23 13:21:58 Ditto.
zerny-google 2014/10/24 12:38:37 Done.
+
+void assertToStringEquals(str, match, testid) {
+ var actual = [];
+ for (int i = 0; i <= match.groupCount; i++) {
+ actual.add(match.group(i));
+ }
+
+ Expect.equals(str,
+ actual.map((s) => (s == null) ? "" : s).join(","),
+ "Test $testid failed");
+}
+
+void shouldBeTrue(actual) => Expect.isTrue(actual);
+void shouldBeFalse(actual) => Expect.isFalse(actual);
+void shouldBeNull(actual) => Expect.isNull(actual);
+
+void shouldBe(actual, expected, [message]) {
+ if (expected == null) {
+ Expect.isNull(actual);
+ } else {
+ Expect.equals(expected.length, actual.groupCount + 1);
+ for (int i = 0; i <= actual.groupCount; i++) {
+ Expect.equals(expected[i], actual.group(i));
+ }
+ }
+}
+
+Match firstMatch(String str, RegExp pattern) => pattern.firstMatch(str);
+List<String> allStringMatches(String str, RegExp pattern) =>
+ pattern.allMatches(str).map((Match m) => m.group(0)).toList();
+
+void description(str) { }

Powered by Google App Engine
This is Rietveld 408576698