OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'util.dart'; |
| 6 import 'package:expect/expect.dart'; |
| 7 |
| 8 void main() { |
| 9 dynamic testForwardSlash(pattern, _string) |
| 10 { |
| 11 var string = _string; |
| 12 |
| 13 var re1 = new RegExp(pattern); |
| 14 |
| 15 return re1.hasMatch(string); |
| 16 } |
| 17 |
| 18 dynamic testLineTerminator(pattern) |
| 19 { |
| 20 var re1 = new RegExp(pattern); |
| 21 |
| 22 return new RegExp(r"\n|\r|\u2028|\u2029").hasMatch(re1.toString()); |
| 23 } |
| 24 |
| 25 // These strings are equivalent, since the '\' is identity escaping the '/' at
the string level. |
| 26 shouldBeTrue(testForwardSlash("^/\$", "/")); |
| 27 shouldBeTrue(testForwardSlash("^\/\$", "/")); |
| 28 // This string passes "^\/$" to the RegExp, so the '/' is escaped in the re! |
| 29 shouldBeTrue(testForwardSlash("^\\/\$", "/")); |
| 30 // These strings pass "^\\/$" and "^\\\/$" respectively to the RegExp, giving
one '\' to match. |
| 31 shouldBeTrue(testForwardSlash("^\\\\/\$", "\\/")); |
| 32 shouldBeTrue(testForwardSlash("^\\\\\\/\$", "\\/")); |
| 33 // These strings match two backslashes (the second with the '/' escaped). |
| 34 shouldBeTrue(testForwardSlash("^\\\\\\\\/\$", "\\\\/")); |
| 35 shouldBeTrue(testForwardSlash("^\\\\\\\\\\/\$", "\\\\/")); |
| 36 // Test that nothing goes wrongif there are multiple forward slashes! |
| 37 shouldBeTrue(testForwardSlash("x/x/x", "x/x/x")); |
| 38 shouldBeTrue(testForwardSlash("x\\/x/x", "x/x/x")); |
| 39 shouldBeTrue(testForwardSlash("x/x\\/x", "x/x/x")); |
| 40 shouldBeTrue(testForwardSlash("x\\/x\\/x", "x/x/x")); |
| 41 |
| 42 shouldBeFalse(testLineTerminator("\\n")); |
| 43 shouldBeFalse(testLineTerminator("\\\\n")); |
| 44 shouldBeFalse(testLineTerminator("\\r")); |
| 45 shouldBeFalse(testLineTerminator("\\\\r")); |
| 46 shouldBeFalse(testLineTerminator("\\u2028")); |
| 47 shouldBeFalse(testLineTerminator("\\\\u2028")); |
| 48 shouldBeFalse(testLineTerminator("\\u2029")); |
| 49 shouldBeFalse(testLineTerminator("\\\\u2029")); |
| 50 } |
OLD | NEW |