Chromium Code Reviews| Index: tests/corelib/regexp/v8_regexp_utils.dart |
| diff --git a/tests/corelib/regexp/v8_regexp_utils.dart b/tests/corelib/regexp/v8_regexp_utils.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..74d6bb5f56210870453c0e7b844904b54dbd40fa |
| --- /dev/null |
| +++ b/tests/corelib/regexp/v8_regexp_utils.dart |
| @@ -0,0 +1,51 @@ |
| +// 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/29 11:25:31
to->for
(or, avoiding passive tense, "to easily po
zerny-google
2014/10/30 11:31:28
Done.
|
| + |
| +import "package:expect/expect.dart"; |
| + |
| +void assertEquals(actual, expected, [String message = null]) { |
| + Expect.equals(actual, expected, message); |
| +} |
| +void assertTrue(actual, [String message = null]) { Expect.isTrue(actual, message); } |
| +void assertFalse(actual, [String message = null]) { Expect.isFalse(actual, message); } |
| +void assertThrows(fn, [num testid = null]) { |
| + Expect.throws(fn, null, "Test $testid failed"); |
|
Lasse Reichstein Nielsen
2014/10/29 11:25:31
Don't need to say "failed" here, this message is o
zerny-google
2014/10/30 11:31:28
Done.
|
| +} |
| +void assertNull(actual, [num testid = null]) { |
| + Expect.isNull(actual, "Test $testid failed"); |
| +} |
| + |
| +void assertToStringEquals(str, match, num testid) { |
| + var actual = []; |
| + for (int i = 0; i <= match.groupCount; i++) { |
| + actual.add(match.group(i)); |
|
Lasse Reichstein Nielsen
2014/10/29 11:25:31
You can convert null to "" here, and avoid the "ma
zerny-google
2014/10/30 11:31:28
Done.
|
| + } |
| + |
| + 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, [String message = null]) { |
| + if (expected == null) { |
| + Expect.isNull(actual, message); |
| + } else { |
| + Expect.equals(expected.length, actual.groupCount + 1); |
| + for (int i = 0; i <= actual.groupCount; i++) { |
| + Expect.equals(expected[i], actual.group(i), message); |
| + } |
| + } |
| +} |
| + |
| +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) { } |