Skip to content

Add -IgnoreOrder to Should-ContainCollection - #2925

Merged
nohwnd merged 1 commit into
mainfrom
inv/2874-ignoreorder
Jul 31, 2026
Merged

Add -IgnoreOrder to Should-ContainCollection#2925
nohwnd merged 1 commit into
mainfrom
inv/2874-ignoreorder

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 31, 2026

Copy link
Copy Markdown
Member

Fix #2874

Should-ContainCollection requires the expected items in the same order, which is annoying when migrating from Should -BeIn where the order did not matter. This adds an -IgnoreOrder switch that only checks that the expected items are present, in any order.

'b',3,2,'a',$null | Should-ContainCollection 'a',2,$null -IgnoreOrder

The check is a multiset subset (new internal Is-CollectionSubset), so duplicates and $null are handled correctly, each expected item is matched at most once. Without the switch the ordered behavior is unchanged.

Added tests for the ordered and unordered cases, duplicates and $null.

🤖

@nohwnd nohwnd added this to the 6.1.0 milestone Jul 31, 2026
@nohwnd
nohwnd merged commit 9739003 into main Jul 31, 2026
13 checks passed
@nohwnd
nohwnd deleted the inv/2874-ignoreorder branch July 31, 2026 14:52
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.

Allow different order in collections

1 participant