summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/regexp_parse.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/jit-test/lib/regexp_parse.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/jit-test/lib/regexp_parse.js')
-rw-r--r--js/src/jit-test/lib/regexp_parse.js205
1 files changed, 205 insertions, 0 deletions
diff --git a/js/src/jit-test/lib/regexp_parse.js b/js/src/jit-test/lib/regexp_parse.js
new file mode 100644
index 000000000..ac6ec02f3
--- /dev/null
+++ b/js/src/jit-test/lib/regexp_parse.js
@@ -0,0 +1,205 @@
+load(libdir + "asserts.js");
+
+// helper functions
+
+function Disjunction(alternatives) {
+ return{
+ type: "Disjunction",
+ alternatives: alternatives
+ };
+}
+
+function Alternative(nodes) {
+ return {
+ type: "Alternative",
+ nodes: nodes
+ };
+}
+
+function Empty() {
+ return {
+ type: "Empty"
+ };
+}
+
+function Text(elements) {
+ return {
+ type: "Text",
+ elements: elements
+ };
+}
+
+function Assertion(type) {
+ return {
+ type: "Assertion",
+ assertion_type: type
+ };
+}
+
+function Atom(data) {
+ return {
+ type: "Atom",
+ data: data
+ };
+}
+
+const kInfinity = 0x7FFFFFFF;
+function Quantifier(min, max, type, body) {
+ return {
+ type: "Quantifier",
+ min: min,
+ max: max,
+ quantifier_type: type,
+ body: body
+ };
+}
+
+function Lookahead(body) {
+ return {
+ type: "Lookahead",
+ is_positive: true,
+ body: body
+ };
+}
+
+function NegativeLookahead(body) {
+ return {
+ type: "Lookahead",
+ is_positive: false,
+ body: body
+ };
+}
+
+function BackReference(index) {
+ return {
+ type: "BackReference",
+ index: index
+ };
+}
+
+function CharacterClass(ranges) {
+ return {
+ type: "CharacterClass",
+ is_negated: false,
+ ranges: ranges.map(([from, to]) => ({ from ,to }))
+ };
+}
+
+function NegativeCharacterClass(ranges) {
+ return {
+ type: "CharacterClass",
+ is_negated: true,
+ ranges: ranges.map(([from, to]) => ({ from ,to }))
+ };
+}
+
+function Capture(index, body) {
+ return {
+ type: "Capture",
+ index: index,
+ body: body
+ };
+}
+
+function AllSurrogateAndCharacterClass(ranges) {
+ return Disjunction([
+ CharacterClass(ranges),
+ Alternative([
+ CharacterClass([["\uD800", "\uDBFF"]]),
+ NegativeLookahead(CharacterClass([["\uDC00", "\uDFFF"]]))
+ ]),
+ Alternative([
+ Assertion("NOT_AFTER_LEAD_SURROGATE"),
+ CharacterClass([["\uDC00", "\uDFFF"]])
+ ]),
+ Text([
+ CharacterClass([["\uD800", "\uDBFF"]]),
+ CharacterClass([["\uDC00", "\uDFFF"]])
+ ])
+ ]);
+}
+
+// testing functions
+
+var all_flags = [
+ "",
+ "i",
+ "m",
+ "u",
+ "im",
+ "iu",
+ "mu",
+ "imu",
+];
+
+var no_unicode_flags = [
+ "",
+ "i",
+ "m",
+ "im",
+];
+
+var unicode_flags = [
+ "u",
+ "iu",
+ "mu",
+ "imu",
+];
+
+var no_multiline_flags = [
+ "",
+ "i",
+ "u",
+ "iu",
+];
+
+var multiline_flags = [
+ "m",
+ "im",
+ "mu",
+ "imu",
+];
+
+function test_flags(pattern, flags, match_only, expected) {
+ for (var flag of flags) {
+ assertDeepEq(parseRegExp(pattern, flag, match_only), expected);
+ }
+}
+
+function make_mix(tree) {
+ if (tree.type == "Atom") {
+ return Atom("X" + tree.data + "Y");
+ }
+ if (tree.type == "CharacterClass") {
+ return Text([
+ Atom("X"),
+ tree,
+ Atom("Y")
+ ]);
+ }
+ if (tree.type == "Alternative") {
+ return Alternative([
+ Atom("X"),
+ ...tree.nodes,
+ Atom("Y")
+ ]);
+ }
+ return Alternative([
+ Atom("X"),
+ tree,
+ Atom("Y")
+ ]);
+}
+
+function test_mix(pattern, flags, expected) {
+ test_flags(pattern, flags, false, expected);
+ test_flags("X" + pattern + "Y", flags, false, make_mix(expected));
+}
+
+function test(pattern, flags, expected) {
+ test_flags(pattern, flags, false, expected);
+}
+
+function test_match_only(pattern, flags, expected) {
+ test_flags(pattern, flags, true, expected);
+}