| Index: tests/language/regex/toString_test.dart
|
| diff --git a/tests/language/regex/toString_test.dart b/tests/language/regex/toString_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ba041ce1fa87006800741de5f00351e5dc4b7b90
|
| --- /dev/null
|
| +++ b/tests/language/regex/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"));
|
| +}
|
|
|