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 /* Many of the Mozilla regexp tests used 'toSource' to test their |
| 10 * results. Since we don't currently support toSource, those tests |
| 11 * are disabled and standalone versions are included here. |
| 12 */ |
| 13 |
| 14 // Tests from ecma_3/RegExp/regress-78156.js |
| 15 var string = 'aaa\n789\r\nccc\r\n345'; |
| 16 var pattern = new RegExp(r"^\d", multiLine: true); |
| 17 var result = pattern.allMatches(string).toList(); |
| 18 assertEquals(2, result.length, "1"); |
| 19 assertEquals('7', result[0].group(0), "2"); |
| 20 assertEquals('3', result[1].group(0), "3"); |
| 21 |
| 22 pattern = new RegExp(r"\d$", multiLine: true); |
| 23 result = pattern.allMatches(string).toList(); |
| 24 assertEquals(2, result.length, "4"); |
| 25 assertEquals('9', result[0].group(0), "5"); |
| 26 assertEquals('5', result[1].group(0), "6"); |
| 27 |
| 28 string = 'aaa\n789\r\nccc\r\nddd'; |
| 29 pattern = new RegExp(r"^\d", multiLine: true); |
| 30 result = pattern.allMatches(string).toList(); |
| 31 assertEquals(1, result.length, "7"); |
| 32 assertEquals('7', result[0].group(0), "8"); |
| 33 |
| 34 pattern = new RegExp(r"\d$", multiLine: true); |
| 35 result = pattern.allMatches(string).toList(); |
| 36 assertEquals(1, result.length, "9"); |
| 37 assertEquals('9', result[0].group(0), "10"); |
| 38 |
| 39 // Tests from ecma_3/RegExp/regress-72964.js |
| 40 pattern = new RegExp(r"[\S]+"); |
| 41 string = '\u00BF\u00CD\u00BB\u00A7'; |
| 42 result = pattern.firstMatch(string); |
| 43 assertEquals(1, result.groupCount + 1, "11"); |
| 44 assertEquals(string, result.group(0), "12"); |
| 45 |
| 46 string = '\u00BF\u00CD \u00BB\u00A7'; |
| 47 result = pattern.firstMatch(string); |
| 48 assertEquals(1, result.groupCount + 1, "13"); |
| 49 assertEquals('\u00BF\u00CD', result.group(0), "14"); |
| 50 |
| 51 string = '\u4e00\uac00\u4e03\u4e00'; |
| 52 result = pattern.firstMatch(string); |
| 53 assertEquals(1, result.groupCount + 1, "15"); |
| 54 assertEquals(string, result.group(0), "16"); |
| 55 |
| 56 string = '\u4e00\uac00 \u4e03\u4e00'; |
| 57 result = pattern.firstMatch(string); |
| 58 assertEquals(1, result.groupCount + 1, "17"); |
| 59 assertEquals('\u4e00\uac00', result.group(0), "18"); |
| 60 } |
OLD | NEW |