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 'Test for proper handling of Unicode RegExps and <a href="http:new RegExp(r"/b
ugzilla.webkit.org/show_bug.cgi?id=7445">bug 7445<")a>: Gmail puts wrong subject
in replies.' |
| 11 ); |
| 12 |
| 13 // Regex to match Re in various languanges straight from Gmail source |
| 14 var I3=new RegExp(r"^\s*(fwd|re|aw|antw|antwort|wg|sv|ang|odp|betreff|betr|tra
nsf|reenv\.|reenv|in|res|resp|resp\.|enc|\u8f6c\u53d1|\u56DE\u590D|\u041F\u0435\
u0440\u0435\u0441\u043B|\u041E\u0442\u0432\u0435\u0442):\s*(.*)$", caseSensitive
: false); |
| 15 |
| 16 // Other RegExs from Gmail source |
| 17 var Ci=new RegExp(r"\s+"); |
| 18 var BC=new RegExp(r"^ "); |
| 19 var BG=new RegExp(r" $"); |
| 20 |
| 21 // This function replaces consecutive whitespace with a single space |
| 22 // then removes a leading and trailing space if they exist. (From Gmail) |
| 23 dynamic Gn(a) { |
| 24 return a.replaceAll(Ci, " ").replaceAll(BC, "").replaceAll(BG, ""); |
| 25 } |
| 26 |
| 27 // Strips leading Re or similar (from Gmail source) |
| 28 dynamic cy(a) { |
| 29 //var b = I3.firstMatch(a); |
| 30 var b = I3.firstMatch(a); |
| 31 |
| 32 if (b != null) { |
| 33 a = b.group(2); |
| 34 } |
| 35 |
| 36 return Gn(a); |
| 37 } |
| 38 |
| 39 assertEquals(cy('Re: Moose'), 'Moose'); |
| 40 assertEquals(cy('\u8f6c\u53d1: Moose'), 'Moose'); |
| 41 |
| 42 // Test handling of \u2820 (skull and crossbones) |
| 43 var sample="sample bm\u2820p cm\\u2820p"; |
| 44 |
| 45 var inlineRe=new RegExp(r".m\u2820p"); |
| 46 assertEquals(inlineRe.firstMatch(sample).group(0), 'bm\u2820p'); |
| 47 |
| 48 |
| 49 // Test handling of \u007c "|" |
| 50 var bsample="sample bm\u007cp cm\\u007cp"; |
| 51 |
| 52 var binlineRe=new RegExp(r".m\u007cp"); |
| 53 |
| 54 assertEquals(binlineRe.firstMatch(bsample).group(0), 'bm|p'); |
| 55 } |
OLD | NEW |