summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/RegExp/sticky.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/RegExp/sticky.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/RegExp/sticky.js')
-rw-r--r--js/src/tests/ecma_6/RegExp/sticky.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/RegExp/sticky.js b/js/src/tests/ecma_6/RegExp/sticky.js
new file mode 100644
index 000000000..13a6debe9
--- /dev/null
+++ b/js/src/tests/ecma_6/RegExp/sticky.js
@@ -0,0 +1,126 @@
+var BUGNUMBER = 773687;
+var summary = 'sticky flag should not break assertion behavior.';
+
+print(BUGNUMBER + ": " + summary);
+
+function test(re, text, expectations) {
+ // Sanity check for test data itself.
+ assertEq(expectations.length, text.length + 1);
+
+ for (var i = 0; i < expectations.length; i++) {
+ var result = expectations[i];
+
+ re.lastIndex = i;
+ var match = re.exec(text);
+ if (result === null) {
+ assertEq(re.lastIndex, 0);
+ assertEq(match, null);
+ } else {
+ assertEq(re.lastIndex, result.lastIndex);
+ assertEq(match !== null, true);
+ assertEq(match.length, result.matches.length);
+ for (var j = 0; j < result.matches.length; j++)
+ assertEq(match[j], result.matches[j]);
+ assertEq(match.index, result.index);
+ }
+ }
+}
+
+// simple text
+test(/bc/y, "abcabd", [
+ null,
+ { lastIndex: 3, matches: ["bc"], index: 1 },
+ null,
+ null,
+ null,
+ null,
+ null,
+]);
+
+// complex pattern
+test(/bc|c|d/y, "abcabd", [
+ null,
+ { lastIndex: 3, matches: ["bc"], index: 1 },
+ { lastIndex: 3, matches: ["c"], index: 2 },
+ null,
+ null,
+ { lastIndex: 6, matches: ["d"], index: 5 },
+ null,
+]);
+
+test(/.*(bc|c|d)/y, "abcabd", [
+ { lastIndex: 6, matches: ["abcabd", "d"], index: 0 },
+ { lastIndex: 6, matches: ["bcabd", "d"], index: 1 },
+ { lastIndex: 6, matches: ["cabd", "d"], index: 2 },
+ { lastIndex: 6, matches: ["abd", "d"], index: 3 },
+ { lastIndex: 6, matches: ["bd", "d"], index: 4 },
+ { lastIndex: 6, matches: ["d", "d"], index: 5 },
+ null,
+]);
+
+test(/.*?(bc|c|d)/y, "abcabd", [
+ { lastIndex: 3, matches: ["abc", "bc"], index: 0 },
+ { lastIndex: 3, matches: ["bc", "bc"], index: 1 },
+ { lastIndex: 3, matches: ["c", "c"], index: 2 },
+ { lastIndex: 6, matches: ["abd", "d"], index: 3 },
+ { lastIndex: 6, matches: ["bd", "d"], index: 4 },
+ { lastIndex: 6, matches: ["d", "d"], index: 5 },
+ null,
+]);
+
+test(/(bc|.*c|d)/y, "abcabd", [
+ { lastIndex: 3, matches: ["abc", "abc"], index: 0 },
+ { lastIndex: 3, matches: ["bc", "bc"], index: 1 },
+ { lastIndex: 3, matches: ["c", "c"], index: 2 },
+ null,
+ null,
+ { lastIndex: 6, matches: ["d", "d"], index: 5 },
+ null,
+]);
+
+// ^ assertions
+test(/^/y, "abcabc", [
+ { lastIndex: 0, matches: [""], index: 0 },
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+]);
+
+test(/^a/my, "abc\nabc", [
+ { lastIndex: 1, matches: ["a"], index: 0 },
+ null,
+ null,
+ null,
+ { lastIndex: 5, matches: ["a"], index: 4 },
+ null,
+ null,
+ null,
+]);
+
+// \b assertions
+test(/\b/y, "abc bc", [
+ { lastIndex: 0, matches: [""], index: 0 },
+ null,
+ null,
+ { lastIndex: 3, matches: [""], index: 3 },
+ { lastIndex: 4, matches: [""], index: 4 },
+ null,
+ { lastIndex: 6, matches: [""], index: 6 },
+]);
+
+// \B assertions
+test(/\B/y, "abc bc", [
+ null,
+ { lastIndex: 1, matches: [""], index: 1 },
+ { lastIndex: 2, matches: [""], index: 2 },
+ null,
+ null,
+ { lastIndex: 5, matches: [""], index: 5 },
+ null,
+]);
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);