mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-04 23:08:39 +09:00
Issue #1726 - Add verification test for string.replaceAll()
This commit is contained in:
parent
00a689060f
commit
4ff9d87cb4
1 changed files with 63 additions and 0 deletions
63
js/src/tests/ecma_2021/manual/test-replaceall.html
Normal file
63
js/src/tests/ecma_2021/manual/test-replaceall.html
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<html><head>
|
||||
<script>
|
||||
function passfail(test) {
|
||||
if (test) {
|
||||
document.writeln('<span style="color:#008000;">PASS</span>');
|
||||
} else {
|
||||
document.writeln('<span style="color:#BF0000;">FAIL</span>');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
Replace "a" with "b":
|
||||
<script>
|
||||
var input='1a234abcd';
|
||||
var match='a';
|
||||
var expected='1b234bbcd';
|
||||
passfail(input.replaceAll(match,'b') === expected);
|
||||
</script><br>
|
||||
Replace "a" with "aa":
|
||||
<script>
|
||||
var input='aabbccdd';
|
||||
var match='a';
|
||||
var expected='aaaabbccdd';
|
||||
passfail(input.replaceAll(match,'aa') === expected);
|
||||
</script><br>
|
||||
Replace "" with "b":
|
||||
<script>
|
||||
var input='aaaa';
|
||||
var match='';
|
||||
var expected='babababab';
|
||||
passfail(input.replaceAll(match,'b') === expected);
|
||||
</script><br>
|
||||
Replace "old" with special pattern "new (was: $&)":
|
||||
<script>
|
||||
var input='This is the old thing of the old time.';
|
||||
var match='old';
|
||||
var expected='This is the new (was: old) thing of the new (was: old) time.';
|
||||
passfail(input.replaceAll(match,'new (was: $&)') === expected);
|
||||
</script><br>
|
||||
Replace "/[0-9]/g" with "b":
|
||||
<script>
|
||||
var input='1a234abcd';
|
||||
var match=/[0-9]/g;
|
||||
var expected='babbbabcd';
|
||||
passfail(input.replaceAll(match,'b') === expected);
|
||||
</script><br>
|
||||
Replace "/[0-9]/" with "b" (Throws):
|
||||
<script>
|
||||
var input='1a234abcd';
|
||||
var match=/[0-9]/;
|
||||
var expected='1a234abcd';
|
||||
try {
|
||||
test=input.replaceAll(match,'b');
|
||||
passfail(false);
|
||||
} catch(e) {
|
||||
passfail(true);
|
||||
document.writeln('('+e+')');
|
||||
}
|
||||
</script><br>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue