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 tests for Object.groupBy and Map.groupBy with string items #4038

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/built-ins/Map/groupBy/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2023 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-map.groupby
description: Map.groupBy works for string items
info: |
Map.groupBy ( items, callbackfn )
...
includes: [compareArray.js]
features: [array-grouping, Map]
---*/

const string = '🥰💩🙏😈';
ptomato marked this conversation as resolved.
Show resolved Hide resolved

const map = Map.groupBy(string, function (char) {
return char < '🙏' ? 'before' : 'after';
});

assert.compareArray(Array.from(map.keys()), ['before', 'after']);
assert.compareArray(map.get('before'), ['💩', '😈']);
assert.compareArray(map.get('after'), ['🥰', '🙏']);
22 changes: 22 additions & 0 deletions test/built-ins/Object/groupBy/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2023 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-object.groupby
description: Object.groupBy works for string items
info: |
Object.groupBy ( items, callbackfn )
...
includes: [compareArray.js]
features: [array-grouping]
---*/

const string = '🥰💩🙏😈';

const obj = Object.groupBy(string, function (char) {
return char < '🙏' ? 'before' : 'after';
});

assert.compareArray(Object.keys(obj), ['before', 'after']);
assert.compareArray(obj.before, ['💩', '😈']);
assert.compareArray(obj.after, ['🥰', '🙏']);
Loading