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 description( |
| 10 "This test checks Unicode in negative RegExp character classes." |
| 11 ); |
| 12 |
| 13 dynamic testPassed(str) { } |
| 14 dynamic testFailed(str) => Expect.fail(str); |
| 15 |
| 16 dynamic test(pattern, str, expected_length) { |
| 17 var result = str.replaceAll(new RegExp(pattern, caseSensitive: false, multiL
ine: true), ''); |
| 18 |
| 19 if (result.length == expected_length) |
| 20 testPassed('"' + pattern + '", ' + '"' + str + '".'); |
| 21 else |
| 22 testFailed('"' + pattern + '", ' + '"' + str + '". Was "' + result + '".')
; |
| 23 } |
| 24 |
| 25 |
| 26 test("\\s", " \t\f\v\r\n", 0); // ASCII whitespace. |
| 27 test("\\S", "Проверка", 0); // Cyrillic letters are non-whitespace... |
| 28 test("\\s", "Проверка", 8); // ...and they aren't whitespace. |
| 29 test("[\\s]", "Проверка", 8); |
| 30 test("[\\S]", "Проверка", 0); |
| 31 test("[^\\s]", "Проверка", 0); |
| 32 test("[^\\S]", "Проверка", 8); |
| 33 test("[\\s\\S]*", "\\u2002Проверка\\r\\n\\u00a0", 0); |
| 34 test("\\S\\S", "уф", 0); |
| 35 test("\\S{2}", "уф", 0); |
| 36 |
| 37 test("\\w", "Проверка", 8); // Alas, only ASCII characters count as word ones
in JS. |
| 38 test("\\W", "Проверка", 0); |
| 39 test("[\\w]", "Проверка", 8); |
| 40 test("[\\W]", "Проверка", 0); |
| 41 test("[^\\w]", "Проверка", 0); |
| 42 test("[^\\W]", "Проверка", 8); |
| 43 test("\\W\\W", "уф", 0); |
| 44 test("\\W{2}", "уф", 0); |
| 45 |
| 46 test("\\d", "Проверка", 8); // Digit and non-digit. |
| 47 test("\\D", "Проверка", 0); |
| 48 test("[\\d]", "Проверка", 8); |
| 49 test("[\\D]", "Проверка", 0); |
| 50 test("[^\\d]", "Проверка", 0); |
| 51 test("[^\\D]", "Проверка", 8); |
| 52 test("\\D\\D", "уф", 0); |
| 53 test("\\D{2}", "уф", 0); |
| 54 |
| 55 test("[\\S\\d]", "Проверка123", 0); |
| 56 test("[\\d\\S]", "Проверка123", 0); |
| 57 test("[^\\S\\d]", "Проверка123", 11); |
| 58 test("[^\\d\\S]", "Проверка123", 11); |
| 59 |
| 60 test("[ \\S]", " Проверка ", 0); |
| 61 test("[\\S ]", " Проверка ", 0); |
| 62 test("[ф \\S]", " Проверка ", 0); |
| 63 test("[\\Sф ]", " Проверка ", 0); |
| 64 |
| 65 test("[^р\\S]", " Проверка ", 8); |
| 66 test("[^\\Sр]", " Проверка ", 8); |
| 67 test("[^р\\s]", " Проверка ", 4); |
| 68 test("[^\\sр]", " Проверка ", 4); |
| 69 |
| 70 test("[ф \\s\\S]", "Проверка \\r\\n", 0); |
| 71 test("[\\S\\sф ]", "Проверка \\r\\n", 0); |
| 72 |
| 73 test("[^z]", "Проверка \\r\\n", 0); |
| 74 test("[^ф]", "Проверка \\r\\n", 0); |
| 75 } |
OLD | NEW |