blob: 6432e6beb3e0b6675d3589c42430e573f39f04b3 [file] [log] [blame]
String.replace(…) test — $&, $`, $' and $nn
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS testString is "It's the end of the world as we know it, and I feel fine."
PASS testString.replace(/I feel/, 'yet $& just') is "It's the end of the world as we know it, and yet I feel just fine."
PASS testString.replace(/the end/, 'nice. $`a picture') is "It's nice. It's a picture of the world as we know it, and I feel fine."
PASS testString.replace(/feel fin/, "am gon$' By") is "It's the end of the world as we know it, and I am gone. Bye."
PASS testString.replace(/(t)(h)(e e)(n)(d)( o)(f)( )(t)(h)(e )([^r]*)(rld)/, 'not $12olly mammoth') is "It's not woolly mammoth as we know it, and I feel fine."
PASS testString.replace('I feel', 'yet $& just') is "It's the end of the world as we know it, and yet I feel just fine."
PASS testString.replace('the end', 'nice. $`a picture') is "It's nice. It's a picture of the world as we know it, and I feel fine."
PASS testString.replace("feel fin", "am gon$' By") is "It's the end of the world as we know it, and I am gone. Bye."
PASS testString.replace(/end/, '$$ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a') is "It's the $ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a of the world as we know it, and I feel fine."
PASS testString.replace('end', '$$ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a') is "It's the $ $0 $00 $1 $01 $2 $12 $9 $99 $1a $11a of the world as we know it, and I feel fine."
PASS 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') is "It's the $ $0 $00 e e n l w w9 ea ra as we know it, and I feel fine."
PASS ('' + singleChar + singleChar + singleChar).replace('a', 'b') is 'baa'
PASS ('' + twoChar + twoChar + twoChar).replace('a', 'b') is 'baaaaa'
PASS ('' + twoChar + twoChar + twoChar).replace('aa', 'b') is 'baaaa'
PASS ('' + twoChar + twoChar + twoChar).replace('aa', 'bb') is 'bbaaaa'
PASS ('' + twoChar + twoChar + twoChar).replace('a', 'bb') is 'bbaaaaa'
PASS '"'.replace(/([^\])?(["'])/g, '$1\$2') is '"'
PASS successfullyParsed is true
TEST COMPLETE