Created
April 10, 2025 09:40
-
-
Save ntfargo/3263a14e0c4258d61ecbee11b60e5f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <p>PASS if no crash.</p> | |
| <script> | |
| let testNumber = 0; | |
| function compareArray(expected, actual) { | |
| if (!expected && !actual) return true; | |
| if (!expected || !actual) return false; | |
| if (expected.length !== actual.length) return false; | |
| for (let i = 0; i < expected.length; i++) { | |
| if (expected[i] !== actual[i]) return false; | |
| } | |
| return true; | |
| } | |
| function compareGroups(expectedGroups, actualGroups) { | |
| if (!expectedGroups && !actualGroups) return true; | |
| if (!expectedGroups || !actualGroups) return false; | |
| const expectedKeys = Object.keys(expectedGroups); | |
| const actualKeys = Object.keys(actualGroups); | |
| if (expectedKeys.length !== actualKeys.length) return false; | |
| for (const key of expectedKeys) { | |
| if (expectedGroups[key] !== actualGroups[key]) return false; | |
| } | |
| return true; | |
| } | |
| function testRegExp(re, str, exp, groups) { | |
| testNumber++; | |
| if (groups && exp) { | |
| exp.groups = groups; | |
| } | |
| let actual = re.exec(str); | |
| let result = compareArray(exp, actual); | |
| if (exp && exp.groups) { | |
| if (!compareGroups(exp.groups, actual.groups)) { | |
| result = false; | |
| } | |
| } | |
| } | |
| testRegExp(/(?<=($)(N*?)*)x/i, "aabbbccc", null); | |
| testRegExp(/(?<=a(N*?)*)b/i, "aabbbccc", ["b", undefined]); | |
| testRegExp(/(?<=a(b*?)*)bc/i, "aabbccc", ["bc", "b"]); | |
| testRegExp(/(?<=A(?:b*?))bc/i, "aaaaaabbccc", ["bc"]); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment