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