OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. All rights reserved. |
| 2 // Copyright 2012 the V8 project authors. All rights reserved. |
| 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are |
| 5 // met: |
| 6 // |
| 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following |
| 11 // disclaimer in the documentation and/or other materials provided |
| 12 // with the distribution. |
| 13 // * Neither the name of Google Inc. nor the names of its |
| 14 // contributors may be used to endorse or promote products derived |
| 15 // from this software without specific prior written permission. |
| 16 // |
| 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
| 29 import 'v8_regexp_utils.dart'; |
| 30 import 'package:expect/expect.dart'; |
| 31 |
| 32 void main() { |
| 33 // Long string to trigger caching. |
| 34 var string = |
| 35 """Friends, Romans, countrymen, lend me your ears! |
| 36 I come to bury Caesar, not to praise him. |
| 37 The evil that men do lives after them, |
| 38 The good is oft interred with their bones; |
| 39 So let it be with Caesar. The noble Brutus |
| 40 Hath told you Caesar was ambitious; |
| 41 If it were so, it was a grievous fault, |
| 42 And grievously hath Caesar answer'd it. |
| 43 Here, under leave of Brutus and the rest- |
| 44 For Brutus is an honorable man; |
| 45 So are they all, all honorable men- |
| 46 Come I to speak in Caesar's funeral. |
| 47 He was my friend, faithful and just to me; |
| 48 But Brutus says he was ambitious, |
| 49 And Brutus is an honorable man. |
| 50 He hath brought many captives home to Rome, |
| 51 Whose ransoms did the general coffers fill. |
| 52 Did this in Caesar seem ambitious? |
| 53 When that the poor have cried, Caesar hath wept; |
| 54 Ambition should be made of sterner stuff: |
| 55 Yet Brutus says he was ambitious, |
| 56 And Brutus is an honorable man. |
| 57 You all did see that on the Lupercal |
| 58 I thrice presented him a kingly crown, |
| 59 Which he did thrice refuse. Was this ambition? |
| 60 Yet Brutus says he was ambitious, |
| 61 And sure he is an honorable man. |
| 62 I speak not to disprove what Brutus spoke, |
| 63 But here I am to speak what I do know. |
| 64 You all did love him once, not without cause; |
| 65 What cause withholds you then to mourn for him? |
| 66 O judgement, thou art fled to brutish beasts, |
| 67 And men have lost their reason. Bear with me; |
| 68 My heart is in the coffin there with Caesar, |
| 69 And I must pause till it come back to me."""; |
| 70 |
| 71 var replaced = string.replaceAll(new RegExp(r"\b\w+\b"), "foo"); |
| 72 for (var i = 0; i < 3; i++) { |
| 73 assertEquals(replaced, |
| 74 string.replaceAll(new RegExp(r"\b\w+\b"), "foo")); |
| 75 } |
| 76 |
| 77 // Check that the result is in a COW array. |
| 78 var words = string.split(" "); |
| 79 assertEquals("Friends,", words[0]); |
| 80 words[0] = "Enemies,"; |
| 81 words = string.split(" "); |
| 82 assertEquals("Friends,", words[0]); |
| 83 } |
OLD | NEW |