diff options
author | Moonchild <moonchild@palemoon.org> | 2021-02-04 21:29:55 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-02-04 21:29:55 +0000 |
commit | bd9fdeccc7f731450188dce4d7ec21643306988c (patch) | |
tree | d6bbc421b2cf6823683be8cfe3977585855be7fa /js/src/tests/ecma_2021 | |
parent | 9b401e77487f2b57cd1077a239459d726dacd758 (diff) | |
download | uxp-bd9fdeccc7f731450188dce4d7ec21643306988c.tar.gz |
Issue #1726 - Add verification test for string.replaceAll()
Diffstat (limited to 'js/src/tests/ecma_2021')
-rw-r--r-- | js/src/tests/ecma_2021/manual/test-replaceall.html | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/js/src/tests/ecma_2021/manual/test-replaceall.html b/js/src/tests/ecma_2021/manual/test-replaceall.html new file mode 100644 index 0000000000..9f90525493 --- /dev/null +++ b/js/src/tests/ecma_2021/manual/test-replaceall.html @@ -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>
+
|