test262 icon indicating copy to clipboard operation
test262 copied to clipboard

Add test case for `Object.groupBy` / `Map.groupBy` with strings?

Open sosukesuzuki opened this issue 1 year ago • 3 comments

Object.groupBy and Map.groupBy take an iterable, such as an array, as their first argument. This can be any iterable, so they can also accept a string.

const str = "abcd";
const grouped = Object.groupBy(str, (char) => char < 'c' ? "x" : "y");

However, it was discovered that in some implementations, a TypeError was thrown when the first argument was not of object type, so this was not working^1.

What do you think about adding test cases to test262 to cover this?

sosukesuzuki avatar Apr 01 '24 03:04 sosukesuzuki

Sounds great. I'd hope basically all implementation bugs end up with test262 regression tests :-)

ljharb avatar Apr 01 '24 03:04 ljharb

Thank you, I will try to submit a PR.

sosukesuzuki avatar Apr 01 '24 03:04 sosukesuzuki

Following up from #4038, I think it might help to have additional coverage for ASCII strings (to help debuggability in case an implementation gets single characters right but surrogate pairs wrong) and grapheme clusters (like 👨‍👦 being split into 👨, ZWJ, and 👦.)

ptomato avatar Apr 04 '24 19:04 ptomato