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

added tests for Array.prototype.group #3354

Merged
merged 6 commits into from
Sep 14, 2022
Merged

added tests for Array.prototype.group #3354

merged 6 commits into from
Sep 14, 2022

Conversation

polsevev
Copy link
Contributor

Added tests for proposal Array Grouping groupBy

CC @codehag

@rwaldron
Copy link
Contributor

Again, very cool that you jumped right in on these :D we'll also go over this one during our video call on Friday. See you then!!

@rwaldron rwaldron added the valid and in progress Issue is valid, action in progress label Dec 15, 2021
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

This looks great! I compared it against my polyfill's tests, and noticed this PR isn't testing that a non-function callbackfn throws a TypeError, and that the [[Prototype]] of the returned object is null.

Copy link
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

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

The tests are good, I added a few suggestions only.

You may also wanna test:

  • the return type of groupBy
  • assert this value inside the callbackfn w/ and w/o thisArg
  • non-callback values for callbackfn
  • non valid values for the this value
  • tainted callbackfns (throwing an exception).
  • callbackfn calls with terse arrays like [,,,1,,2]
  • array like values for the this value, e.g. [].groupBy.call({length: 2, '1': 'foo'}, callbackfn);

test/built-ins/Array/prototype/groupBy/length.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/name.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/undefined.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/emptyList.js Outdated Show resolved Hide resolved
@ljharb ljharb requested a review from a team May 19, 2022 18:23
@hemanth
Copy link
Member

hemanth commented Jun 8, 2022

This should be group instead of groupBy now.

Copy link
Member

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

#3354 (review)

the return type of groupBy

done.

assert this value inside the callbackfn w/ and w/o thisArg

done.

non-callback values for callbackfn

done.

non valid values for the this value

done.

tainted callbackfns (throwing an exception).

Do we have to?

callbackfn calls with terse arrays like [,,,1,,2]

done.

array like values for the this value, e.g. [].groupBy.call({length: 2, '1': 'foo'}, callbackfn);

Done.

test/built-ins/Array/prototype/groupBy/callback-arg.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/callback-arg.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/emptyList.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/length.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/name.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/null.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/groupBy/undefined.js Outdated Show resolved Hide resolved
@jridgewell jridgewell changed the title added tests for groupBy added tests for group Sep 2, 2022
@jridgewell jridgewell changed the title added tests for group added tests for Array.prototype.group Sep 2, 2022
ptomato
ptomato previously approved these changes Sep 13, 2022
Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks for resuming this PR, and apologies that it took some time to get around to it. (I'll start on groupToMap as soon as possible.) I think this is basically ready to merge. Some small suggestions, but keeping in mind how long this has already taken to review, I've made them into GitHub suggestions that you can just click to accept or not, so that the review process don't cause any more delay on this PR.

I have some suggestions for additional things that could be tested, but for the same reason I wouldn't say that they should block this PR. They can be added in a second PR if you are so inclined:

  • Test throwing on an arraylike with a value of its length property that can't be converted to an integer, or a getter that throws
  • Test throwing in step 6.b if Pk is a property with a getter that throws
  • Test throwing if the callback returns a value that can't be converted to a property key (e.g. an object with a toString method that throws)

Thanks again for resuming this work!

test/built-ins/Array/prototype/group/callback-arg.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/group/emptyList.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/group/groupLength.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/group/sparse-array.js Outdated Show resolved Hide resolved
test/built-ins/Array/prototype/group/sparse-array.js Outdated Show resolved Hide resolved
@ptomato
Copy link
Contributor

ptomato commented Sep 13, 2022

tainted callbackfns (throwing an exception).

Do we have to?

Would be nice, but as with the other suggestions I don't see a need to block this PR on having that.

Another one I thought of: shortening and lengthening the array during the iteration.

@jridgewell
Copy link
Member

Test throwing on an arraylike with a value of its length property that can't be converted to an integer, or a getter that throws

Done.

Test throwing in step 6.b if Pk is a property with a getter that throws

Done.

Test throwing if the callback returns a value that can't be converted to a property key (e.g. an object with a toString method that throws)

Done.

tainted callbackfns (throwing an exception).

Done.

Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@ptomato ptomato merged commit e7af145 into tc39:main Sep 14, 2022
ljharb added a commit that referenced this pull request Sep 14, 2022
ljharb added a commit that referenced this pull request Sep 14, 2022
ljharb added a commit that referenced this pull request Sep 14, 2022
catamorphism pushed a commit to catamorphism/test262 that referenced this pull request Oct 4, 2022
catamorphism pushed a commit to catamorphism/test262 that referenced this pull request Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review valid and in progress Issue is valid, action in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants