Skip to content

Enumerate non-IList collections (hashtable keys/values) in Should -Be#2753

Merged
nohwnd merged 2 commits into
mainfrom
fix/1200-enumerate-collections
Jun 27, 2026
Merged

Enumerate non-IList collections (hashtable keys/values) in Should -Be#2753
nohwnd merged 2 commits into
mainfrom
fix/1200-enumerate-collections

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 25, 2026

Copy link
Copy Markdown
Member

Fix #1200

Should -Be reported two equal collections as different when they were a non-IList enumerable such as the one returned by [hashtable].Keys / .Values. ArraysAreEqual takes its arguments as [object[]], and binding such a collection to an [object[]] parameter wraps it as a single element instead of enumerating it - so the actual value had two items and the expected value had one, and the counts never matched.

Take the arguments as [object] and enumerate them with @() inside the function, which expands these collections correctly while still leaving strings and hashtables as single values. Arrays, scalars and nested arrays compare exactly as before.

Should -Be reported two equal collections as different when they were a non-IList
enumerable such as [hashtable].Keys/.Values. ArraysAreEqual took its arguments as
[object[]], and binding such a collection to an [object[]] parameter wraps it as a
single element instead of enumerating it, so the counts never matched.

Take the arguments as [object] and enumerate them with @() inside the function, which
expands these collections correctly while leaving strings and hashtables as single
values. Arrays, scalars and nested arrays compare exactly as before.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd force-pushed the fix/1200-enumerate-collections branch from fa1bc8a to 7af4e49 Compare June 26, 2026 07:28
Add Queue, Stack, SortedSet and generic Dictionary cases to the #1200
tests, and a generic List case to guard the IList path that already
worked. The collection has to be the -Be argument to hit the bug, since
the piped side is always enumerated by the pipeline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd marked this pull request as ready for review June 27, 2026 09:22
@nohwnd nohwnd merged commit c0d9a0f into main Jun 27, 2026
13 checks passed
@nohwnd nohwnd deleted the fix/1200-enumerate-collections branch June 27, 2026 09:22
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.

Should -Be doesn't enumerate some collections?

1 participant