2 "String.replace(…) test — $&, $`, $' and $nn"
5 var testString
= "It's the end of the world as we know it, and I feel fine.";
7 "\"It's the end of the world as we know it, and I feel fine.\"");
8 shouldBe("testString.replace(/I feel/, 'yet $& just')",
9 "\"It's the end of the world as we know it, and yet I feel just fine.\"");
10 shouldBe("testString.replace(/the end/, 'nice. $`a picture')",
11 "\"It's nice. It's a picture of the world as we know it, and I feel fine.\"");
12 shouldBe('testString.replace(/feel fin/, "am gon$\' By")',
13 "\"It's the end of the world as we know it, and I am gone. Bye.\"");
14 shouldBe("testString.replace(/(t)(h)(e e)(n)(d)( o)(f)( )(t)(h)(e )([^r]*)(rld)/, 'not $12olly mammoth')",
15 "\"It's not woolly mammoth as we know it, and I feel fine.\"");
17 shouldBe("testString.replace('I feel', 'yet $& just')",
18 "\"It's the end of the world as we know it, and yet I feel just fine.\"");
19 shouldBe("testString.replace('the end', 'nice. $`a picture')",
20 "\"It's nice. It's a picture of the world as we know it, and I feel fine.\"");
21 shouldBe('testString.replace("feel fin", "am gon$\' By")',
22 "\"It's the end of the world as we know it, and I am gone. Bye.\"");
24 shouldBe("testString.replace(/end/, '$$ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a')",
25 "\"It's the $ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a of the world as we know it, and I feel fine.\"");
26 shouldBe("testString.replace('end', '$$ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a')",
27 "\"It's the $ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a of the world as we know it, and I feel fine.\"");
29 shouldBe("testString.replace(/(e)(n)(d) (o)(f) (t)(h)(e) (w)(o)(r)(l)(d)/, '$$ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a')",
30 "\"It's the $ $0 $00 e e n l w w9 ea ra as we know it, and I feel fine.\"");
34 shouldBe("('' + singleChar + singleChar + singleChar).replace('a', 'b')", "'baa'");
35 shouldBe("('' + twoChar + twoChar + twoChar).replace('a', 'b')", "'baaaaa'");
36 shouldBe("('' + twoChar + twoChar + twoChar).replace('aa', 'b')", "'baaaa'");
37 shouldBe("('' + twoChar + twoChar + twoChar).replace('aa', 'bb')", "'bbaaaa'");
38 shouldBe("('' + twoChar + twoChar + twoChar).replace('a', 'bb')", "'bbaaaaa'");
40 shouldBe("'\"'.replace(/([^\\])?([\"'])/g, '$1\\$2')", "'\"'");