| 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 = """Friends, Romans, countrymen, lend me your ears! | |
| 35 I come to bury Caesar, not to praise him. | |
| 36 The evil that men do lives after them, | |
| 37 The good is oft interred with their bones; | |
| 38 So let it be with Caesar. The noble Brutus | |
| 39 Hath told you Caesar was ambitious; | |
| 40 If it were so, it was a grievous fault, | |
| 41 And grievously hath Caesar answer'd it. | |
| 42 Here, under leave of Brutus and the rest- | |
| 43 For Brutus is an honorable man; | |
| 44 So are they all, all honorable men- | |
| 45 Come I to speak in Caesar's funeral. | |
| 46 He was my friend, faithful and just to me; | |
| 47 But Brutus says he was ambitious, | |
| 48 And Brutus is an honorable man. | |
| 49 He hath brought many captives home to Rome, | |
| 50 Whose ransoms did the general coffers fill. | |
| 51 Did this in Caesar seem ambitious? | |
| 52 When that the poor have cried, Caesar hath wept; | |
| 53 Ambition should be made of sterner stuff: | |
| 54 Yet Brutus says he was ambitious, | |
| 55 And Brutus is an honorable man. | |
| 56 You all did see that on the Lupercal | |
| 57 I thrice presented him a kingly crown, | |
| 58 Which he did thrice refuse. Was this ambition? | |
| 59 Yet Brutus says he was ambitious, | |
| 60 And sure he is an honorable man. | |
| 61 I speak not to disprove what Brutus spoke, | |
| 62 But here I am to speak what I do know. | |
| 63 You all did love him once, not without cause; | |
| 64 What cause withholds you then to mourn for him? | |
| 65 O judgement, thou art fled to brutish beasts, | |
| 66 And men have lost their reason. Bear with me; | |
| 67 My heart is in the coffin there with Caesar, | |
| 68 And I must pause till it come back to me."""; | |
| 69 | |
| 70 var replaced = string.replaceAll(new RegExp(r"\b\w+\b"), "foo"); | |
| 71 for (var i = 0; i < 3; i++) { | |
| 72 assertEquals(replaced, string.replaceAll(new RegExp(r"\b\w+\b"), "foo")); | |
| 73 } | |
| 74 | |
| 75 // Check that the result is in a COW array. | |
| 76 var words = string.split(" "); | |
| 77 assertEquals("Friends,", words[0]); | |
| 78 words[0] = "Enemies,"; | |
| 79 words = string.split(" "); | |
| 80 assertEquals("Friends,", words[0]); | |
| 81 } | |
| OLD | NEW |