Skip to content

Commit

Permalink
Transform compareArray -> assert.compareArray: test/built-ins/RegExp/…
Browse files Browse the repository at this point in the history
…**/*.js (#3234)
  • Loading branch information
rwaldron authored Oct 6, 2021
1 parent 0f47fe4 commit c44eead
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 85 deletions.
5 changes: 2 additions & 3 deletions test/built-ins/RegExp/named-groups/groups-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ info: |
---*/

// Properties created on result.groups in textual order.
assert(compareArray(["fst", "snd"],
Object.getOwnPropertyNames(
/(?<fst>.)|(?<snd>.)/u.exec("abcd").groups)));
assert.compareArray(["fst", "snd"], Object.getOwnPropertyNames(
/(?<fst>.)|(?<snd>.)/u.exec("abcd").groups));

// Properties are created with Define, not Set
let counter = 0;
Expand Down
29 changes: 14 additions & 15 deletions test/built-ins/RegExp/named-groups/lookbehind.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@ includes: [compareArray.js]
---*/

// Unicode mode
assert(compareArray(["f", "c"], "abcdef".match(/(?<=(?<a>\w){3})f/u)));
assert.compareArray(["f", "c"], "abcdef".match(/(?<=(?<a>\w){3})f/u));
assert.sameValue("c", "abcdef".match(/(?<=(?<a>\w){3})f/u).groups.a);
assert.sameValue("b", "abcdef".match(/(?<=(?<a>\w){4})f/u).groups.a);
assert.sameValue("a", "abcdef".match(/(?<=(?<a>\w)+)f/u).groups.a);
assert.sameValue(null, "abcdef".match(/(?<=(?<a>\w){6})f/u));

assert(compareArray(["f", ""], "abcdef".match(/((?<=\w{3}))f/u)));
assert(compareArray(["f", ""], "abcdef".match(/(?<a>(?<=\w{3}))f/u)));
assert.compareArray(["f", ""], "abcdef".match(/((?<=\w{3}))f/u));
assert.compareArray(["f", ""], "abcdef".match(/(?<a>(?<=\w{3}))f/u));

assert(compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\d){3})f/u)));
assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\d){3})f/u));
assert.sameValue(null, "abcdef".match(/(?<!(?<a>\D){3})f/u));

assert(compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\D){3})f|f/u)));
assert(compareArray(["f", undefined], "abcdef".match(/(?<a>(?<!\D{3}))f|f/u)));
assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\D){3})f|f/u));
assert.compareArray(["f", undefined], "abcdef".match(/(?<a>(?<!\D{3}))f|f/u));

// Non-Unicode mode
assert(compareArray(["f", "c"], "abcdef".match(/(?<=(?<a>\w){3})f/)));
assert.compareArray(["f", "c"], "abcdef".match(/(?<=(?<a>\w){3})f/));
assert.sameValue("c", "abcdef".match(/(?<=(?<a>\w){3})f/).groups.a);
assert.sameValue("b", "abcdef".match(/(?<=(?<a>\w){4})f/).groups.a);
assert.sameValue("a", "abcdef".match(/(?<=(?<a>\w)+)f/).groups.a);
assert.sameValue(null, "abcdef".match(/(?<=(?<a>\w){6})f/));

assert(compareArray(["f", ""], "abcdef".match(/((?<=\w{3}))f/)));
assert(compareArray(["f", ""], "abcdef".match(/(?<a>(?<=\w{3}))f/)));
assert.compareArray(["f", ""], "abcdef".match(/((?<=\w{3}))f/));
assert.compareArray(["f", ""], "abcdef".match(/(?<a>(?<=\w{3}))f/));

assert(compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\d){3})f/)));
assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\d){3})f/));
assert.sameValue(null, "abcdef".match(/(?<!(?<a>\D){3})f/));

assert(compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\D){3})f|f/)));
assert(compareArray(["f", undefined], "abcdef".match(/(?<a>(?<!\D{3}))f|f/)));
assert.compareArray(["f", undefined], "abcdef".match(/(?<!(?<a>\D){3})f|f/));
assert.compareArray(["f", undefined], "abcdef".match(/(?<a>(?<!\D{3}))f|f/));

// Even within a lookbehind, properties are created in left to right order
assert(compareArray(["fst", "snd"],
Object.getOwnPropertyNames(
/(?<=(?<fst>.)|(?<snd>.))/u.exec("abcd").groups)));
assert.compareArray(["fst", "snd"], Object.getOwnPropertyNames(
/(?<=(?<fst>.)|(?<snd>.))/u.exec("abcd").groups));
51 changes: 25 additions & 26 deletions test/built-ins/RegExp/named-groups/non-unicode-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,35 @@ features: [regexp-named-groups]
includes: [compareArray.js]
---*/

assert(compareArray(["a", "a"], "bab".match(/(?<a>a)/)));
assert(compareArray(["a", "a"], "bab".match(/(?<a42>a)/)));
assert(compareArray(["a", "a"], "bab".match(/(?<_>a)/)));
assert(compareArray(["a", "a"], "bab".match(/(?<$>a)/)));
assert(compareArray(["bab", "a"], "bab".match(/.(?<$>a)./)));
assert(compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(.)/)));
assert(compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(?<b>.)/)));
assert(compareArray(["bab", "ab"], "bab".match(/.(?<a>\w\w)/)));
assert(compareArray(["bab", "bab"], "bab".match(/(?<a>\w\w\w)/)));
assert(compareArray(["bab", "ba", "b"], "bab".match(/(?<a>\w\w)(?<b>\w)/)));
assert.compareArray(["a", "a"], "bab".match(/(?<a>a)/));
assert.compareArray(["a", "a"], "bab".match(/(?<a42>a)/));
assert.compareArray(["a", "a"], "bab".match(/(?<_>a)/));
assert.compareArray(["a", "a"], "bab".match(/(?<$>a)/));
assert.compareArray(["bab", "a"], "bab".match(/.(?<$>a)./));
assert.compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(.)/));
assert.compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(?<b>.)/));
assert.compareArray(["bab", "ab"], "bab".match(/.(?<a>\w\w)/));
assert.compareArray(["bab", "bab"], "bab".match(/(?<a>\w\w\w)/));
assert.compareArray(["bab", "ba", "b"], "bab".match(/(?<a>\w\w)(?<b>\w)/));

let {a, b, c} = /(?<a>.)(?<b>.)(?<c>.)\k<c>\k<b>\k<a>/.exec("abccba").groups;
assert.sameValue(a, "a");
assert.sameValue(b, "b");
assert.sameValue(c, "c");

assert(compareArray("bab".match(/(a)/), "bab".match(/(?<a>a)/)));
assert(compareArray("bab".match(/(a)/), "bab".match(/(?<a42>a)/)));
assert(compareArray("bab".match(/(a)/), "bab".match(/(?<_>a)/)));
assert(compareArray("bab".match(/(a)/), "bab".match(/(?<$>a)/)));
assert(compareArray("bab".match(/.(a)./), "bab".match(/.(?<$>a)./)));
assert(compareArray("bab".match(/.(a)(.)/), "bab".match(/.(?<a>a)(.)/)));
assert(compareArray("bab".match(/.(a)(.)/), "bab".match(/.(?<a>a)(?<b>.)/)));
assert(compareArray("bab".match(/.(\w\w)/), "bab".match(/.(?<a>\w\w)/)));
assert(compareArray("bab".match(/(\w\w\w)/), "bab".match(/(?<a>\w\w\w)/)));
assert(compareArray("bab".match(/(\w\w)(\w)/), "bab".match(/(?<a>\w\w)(?<b>\w)/)));
assert.compareArray("bab".match(/(a)/), "bab".match(/(?<a>a)/));
assert.compareArray("bab".match(/(a)/), "bab".match(/(?<a42>a)/));
assert.compareArray("bab".match(/(a)/), "bab".match(/(?<_>a)/));
assert.compareArray("bab".match(/(a)/), "bab".match(/(?<$>a)/));
assert.compareArray("bab".match(/.(a)./), "bab".match(/.(?<$>a)./));
assert.compareArray("bab".match(/.(a)(.)/), "bab".match(/.(?<a>a)(.)/));
assert.compareArray("bab".match(/.(a)(.)/), "bab".match(/.(?<a>a)(?<b>.)/));
assert.compareArray("bab".match(/.(\w\w)/), "bab".match(/.(?<a>\w\w)/));
assert.compareArray("bab".match(/(\w\w\w)/), "bab".match(/(?<a>\w\w\w)/));
assert.compareArray("bab".match(/(\w\w)(\w)/), "bab".match(/(?<a>\w\w)(?<b>\w)/));

assert(compareArray(["bab", "b"], "bab".match(/(?<b>b).\1/)));
assert(compareArray(["baba", "b", "a"], "baba".match(/(.)(?<a>a)\1\2/)));
assert(compareArray(["baba", "b", "a", "b", "a"],
"baba".match(/(.)(?<a>a)(?<b>\1)(\2)/)));
assert(compareArray(["<a", "<"], "<a".match(/(?<lt><)a/)));
assert(compareArray([">a", ">"], ">a".match(/(?<gt>>)a/)));
assert.compareArray(["bab", "b"], "bab".match(/(?<b>b).\1/));
assert.compareArray(["baba", "b", "a"], "baba".match(/(.)(?<a>a)\1\2/));
assert.compareArray(["baba", "b", "a", "b", "a"], "baba".match(/(.)(?<a>a)(?<b>\1)(\2)/));
assert.compareArray(["<a", "<"], "<a".match(/(?<lt><)a/));
assert.compareArray([">a", ">"], ">a".match(/(?<gt>>)a/));
12 changes: 6 additions & 6 deletions test/built-ins/RegExp/named-groups/non-unicode-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ includes: [compareArray.js]
---*/

// Named references.
assert(compareArray(["bab", "b"], "bab".match(/(?<b>.).\k<b>/)));
assert.compareArray(["bab", "b"], "bab".match(/(?<b>.).\k<b>/));
assert.sameValue(null, "baa".match(/(?<b>.).\k<b>/));

// Reference inside group.
assert(compareArray(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../)));
assert.compareArray(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../));
assert.sameValue("b", "bab".match(/(?<a>\k<a>\w)../).groups.a);

// Reference before group.
assert(compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/)));
assert.compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/));
assert.sameValue("b", "bab".match(/\k<a>(?<a>b)\w\k<a>/).groups.a);
assert(compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/)));
assert.compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/));
let {a, b} = "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/).groups;
assert.sameValue(a, "a");
assert.sameValue(b, "b");

assert(compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/)));
assert(compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/)));
assert.compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/));
assert.compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/));

// Reference properties.
assert.sameValue("a", /(?<a>a)(?<b>b)\k<a>/.exec("aba").groups.a);
Expand Down
56 changes: 27 additions & 29 deletions test/built-ins/RegExp/named-groups/unicode-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,39 @@ features: [regexp-named-groups]
includes: [compareArray.js]
---*/

assert(compareArray(["a", "a"], "bab".match(/(?<a>a)/u)));
assert(compareArray(["a", "a"], "bab".match(/(?<a42>a)/u)));
assert(compareArray(["a", "a"], "bab".match(/(?<_>a)/u)));
assert(compareArray(["a", "a"], "bab".match(/(?<$>a)/u)));
assert(compareArray(["bab", "a"], "bab".match(/.(?<$>a)./u)));
assert(compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(.)/u)));
assert(compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(?<b>.)/u)));
assert(compareArray(["bab", "ab"], "bab".match(/.(?<a>\w\w)/u)));
assert(compareArray(["bab", "bab"], "bab".match(/(?<a>\w\w\w)/u)));
assert(compareArray(["bab", "ba", "b"], "bab".match(/(?<a>\w\w)(?<b>\w)/u)));
assert.compareArray(["a", "a"], "bab".match(/(?<a>a)/u));
assert.compareArray(["a", "a"], "bab".match(/(?<a42>a)/u));
assert.compareArray(["a", "a"], "bab".match(/(?<_>a)/u));
assert.compareArray(["a", "a"], "bab".match(/(?<$>a)/u));
assert.compareArray(["bab", "a"], "bab".match(/.(?<$>a)./u));
assert.compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(.)/u));
assert.compareArray(["bab", "a", "b"], "bab".match(/.(?<a>a)(?<b>.)/u));
assert.compareArray(["bab", "ab"], "bab".match(/.(?<a>\w\w)/u));
assert.compareArray(["bab", "bab"], "bab".match(/(?<a>\w\w\w)/u));
assert.compareArray(["bab", "ba", "b"], "bab".match(/(?<a>\w\w)(?<b>\w)/u));

let {a, b, c} = /(?<a>.)(?<b>.)(?<c>.)\k<c>\k<b>\k<a>/u.exec("abccba").groups;
assert.sameValue(a, "a");
assert.sameValue(b, "b");
assert.sameValue(c, "c");

assert(compareArray("bab".match(/(a)/u), "bab".match(/(?<a>a)/u)));
assert(compareArray("bab".match(/(a)/u), "bab".match(/(?<a42>a)/u)));
assert(compareArray("bab".match(/(a)/u), "bab".match(/(?<_>a)/u)));
assert(compareArray("bab".match(/(a)/u), "bab".match(/(?<$>a)/u)));
assert(compareArray("bab".match(/.(a)./u), "bab".match(/.(?<$>a)./u)));
assert(compareArray("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(.)/u)));
assert(compareArray("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(?<b>.)/u)));
assert(compareArray("bab".match(/.(\w\w)/u), "bab".match(/.(?<a>\w\w)/u)));
assert(compareArray("bab".match(/(\w\w\w)/u), "bab".match(/(?<a>\w\w\w)/u)));
assert(compareArray("bab".match(/(\w\w)(\w)/u), "bab".match(/(?<a>\w\w)(?<b>\w)/u)));
assert.compareArray("bab".match(/(a)/u), "bab".match(/(?<a>a)/u));
assert.compareArray("bab".match(/(a)/u), "bab".match(/(?<a42>a)/u));
assert.compareArray("bab".match(/(a)/u), "bab".match(/(?<_>a)/u));
assert.compareArray("bab".match(/(a)/u), "bab".match(/(?<$>a)/u));
assert.compareArray("bab".match(/.(a)./u), "bab".match(/.(?<$>a)./u));
assert.compareArray("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(.)/u));
assert.compareArray("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(?<b>.)/u));
assert.compareArray("bab".match(/.(\w\w)/u), "bab".match(/.(?<a>\w\w)/u));
assert.compareArray("bab".match(/(\w\w\w)/u), "bab".match(/(?<a>\w\w\w)/u));
assert.compareArray("bab".match(/(\w\w)(\w)/u), "bab".match(/(?<a>\w\w)(?<b>\w)/u));

assert(compareArray(["bab", "b"], "bab".match(/(?<b>b).\1/u)));
assert(compareArray(["baba", "b", "a"], "baba".match(/(.)(?<a>a)\1\2/u)));
assert(compareArray(["baba", "b", "a", "b", "a"],
"baba".match(/(.)(?<a>a)(?<b>\1)(\2)/u)));
assert(compareArray(["<a", "<"], "<a".match(/(?<lt><)a/u)));
assert(compareArray([">a", ">"], ">a".match(/(?<gt>>)a/u)));
assert.compareArray(["bab", "b"], "bab".match(/(?<b>b).\1/u));
assert.compareArray(["baba", "b", "a"], "baba".match(/(.)(?<a>a)\1\2/u));
assert.compareArray(["baba", "b", "a", "b", "a"], "baba".match(/(.)(?<a>a)(?<b>\1)(\2)/u));
assert.compareArray(["<a", "<"], "<a".match(/(?<lt><)a/u));
assert.compareArray([">a", ">"], ">a".match(/(?<gt>>)a/u));

// Nested groups.
assert(compareArray(["bab", "bab", "ab", "b"], "bab".match(/(?<a>.(?<b>.(?<c>.)))/u)));
assert(compareArray({a: "bab", b: "ab", c: "b"},
"bab".match(/(?<a>.(?<b>.(?<c>.)))/u).groups));
assert.compareArray(["bab", "bab", "ab", "b"], "bab".match(/(?<a>.(?<b>.(?<c>.)))/u));
assert.compareArray({a: "bab", b: "ab", c: "b"}, "bab".match(/(?<a>.(?<b>.(?<c>.)))/u).groups);
12 changes: 6 additions & 6 deletions test/built-ins/RegExp/named-groups/unicode-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ includes: [compareArray.js]
---*/

// Named references.
assert(compareArray(["bab", "b"], "bab".match(/(?<b>.).\k<b>/u)));
assert.compareArray(["bab", "b"], "bab".match(/(?<b>.).\k<b>/u));
assert.sameValue(null, "baa".match(/(?<b>.).\k<b>/u));

// Reference inside group.
assert(compareArray(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../u)));
assert.compareArray(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../u));
assert.sameValue("b", "bab".match(/(?<a>\k<a>\w)../u).groups.a);

// Reference before group.
assert(compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/u)));
assert.compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/u));
assert.sameValue("b", "bab".match(/\k<a>(?<a>b)\w\k<a>/u).groups.a);
assert(compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/u)));
assert.compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/u));
let {a, b} = "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/u).groups;
assert.sameValue(a, "a");
assert.sameValue(b, "b");

assert(compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/)));
assert(compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/)));
assert.compareArray(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/));
assert.compareArray(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/));

// Reference properties.
assert.sameValue("a", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").groups.a);
Expand Down

0 comments on commit c44eead

Please sign in to comment.