summaryrefslogtreecommitdiff
path: root/js/src/tests
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2021-02-04 21:29:55 +0000
committerMoonchild <moonchild@palemoon.org>2021-02-04 21:29:55 +0000
commit0d79cccf0642d77842c1aa85bd544de37147ba4b (patch)
treed6bbc421b2cf6823683be8cfe3977585855be7fa /js/src/tests
parent8775c5de981f1b215343e70629725906f18b5020 (diff)
downloadaura-central-0d79cccf0642d77842c1aa85bd544de37147ba4b.tar.gz
Issue mcp-graveyard/UXP%1726 - Add verification test for string.replaceAll()
Diffstat (limited to 'js/src/tests')
-rw-r--r--js/src/tests/ecma_2021/manual/test-replaceall.html63
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 000000000..9f9052549
--- /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>
+