Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic u flag tests in v flag tests. #4241

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

tannal
Copy link
Contributor

@tannal tannal commented Sep 27, 2024

A follow up pr for #4213.

  • Add some basic u flag tests along with the v flag tests.
  • Use the compareArray method for better error message in the matchAll test (and others).

@tannal tannal requested a review from a team as a code owner September 27, 2024 01:11
undefined,
"Non-ASCII with v flag"
);
reportCompare(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reportCompare(0, 0);
reportCompare(0, 0);

The lint test seems to be failing due to this missing newline in the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the guidance.

@ioannad
Copy link
Contributor

ioannad commented Sep 27, 2024

@tannal thanks for the followup PR! I think it would be better to add the u flag tests to separate files, or alternatively to rename the test files to mention the u flag as well, e.g., test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-u-flag.js.

Copy link
Contributor

@ioannad ioannad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some suggestions to have the tests passing, however, there are two tests in test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-u-flag.js that fail unexpectedly. We could remove them for now but I would prefer if we knew why they are failing and how to fix them.

return result ? [result[0], result.index] : null;
}

assert.compareArray(doExec(/𠮷/), ["𠮷", 0], "Basic exec without v flag");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this line removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine both to keep it or remove it because the behavior of an empty flag is already caught by other tests. I've added it back in the newest revision.

assert.compareArray(/\P{ASCII}/u.exec(complexText), ["\u{20BB7}"], "Non-ASCII with u flag");
assert.compareArray(/\P{ASCII}/v.exec(complexText), ["\u{20BB7}"], "Non-ASCII with v flag");

reportCompare(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reportCompare(0, 0);

This undefined function is called in the end of every file. Is this accidental or am I overlooking something?

Copy link
Contributor Author

@tannal tannal Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake, I will remove them.
Thanks for pointing out.
reportCompare is used in the spidermonkey codebase.


assert.sameValue(doMatch(/x/u), null, "Non-matching regex with u flag");
assert.sameValue(doMatch(/x/v), null, "Non-matching regex with v flag");
reportCompare(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reportCompare(0, 0);

Same.

undefined,
"Non-ASCII with v flag"
);
reportCompare(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reportCompare(0, 0);

Same.

assert.sameValue(doReplace(/\p{Script=Han}/gu, 'X'), "XaXbX", "Unicode property escapes with u flag");
assert.sameValue(doReplace(/\p{Script=Han}/gv, 'X'), "XaXbX", "Unicode property escapes with v flag");

reportCompare(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reportCompare(0, 0);

Same.

// Non-existent pattern
assert.sameValue(doSearch(/x/u), -1, "Search for non-existent pattern with u flag");
assert.sameValue(doSearch(/x/v), -1, "Search for non-existent pattern with v flag");
reportCompare(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reportCompare(0, 0);

Same.

Comment on lines 60 to 70
assert.sameValue(
doMatchAll(/(?:)/gu).length,
6,
"Empty matches with u flag"
);

assert.sameValue(
doMatchAll(/(?:)/gv).length,
6,
"Empty matches with v flag"
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two tests seem to fail on my side on V8, JSC, SpiderMonkey, and Node. This is unexpected, since the second test was there already added in the previous PR #4213.

Copy link
Contributor Author

@tannal tannal Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I think it's because I flat the array of [m[0], m.index] in doMatchAll.
It should be 12 now, I will fix this later.
Thanks for the feedback.

@tannal
Copy link
Contributor Author

tannal commented Oct 4, 2024

Thanks for all the feedback. I greatly appreciate your time and assistance.
I think all of the issues are resolved now.

@ioannad ioannad merged commit 36f5cad into tc39:main Oct 4, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants