Skip to content

Commit 688b06c

Browse files
committed
Add case-sensitive operator tests for switch parameter explicit $false handling
1 parent 357e79c commit 688b06c

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

‎test/powershell/Modules/Microsoft.PowerShell.Core/Where-Object.Tests.ps1‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,5 +280,104 @@ Describe "Where-Object" -Tags "CI" {
280280
# Similar behavior for -Like:$false with -Value
281281
{ $testData | Where-Object Name -Like:$false -Value 'A*' } | Should -Throw -ErrorId 'OperatorNotSpecified,Microsoft.PowerShell.Commands.WhereObjectCommand'
282282
}
283+
284+
It "-CEQ:`$false should behave like default boolean evaluation" {
285+
# With -CEQ:$false, the parameter is not specified, so default boolean evaluation applies
286+
$result = $testData | Where-Object Name -CEQ:$false
287+
$result | Should -HaveCount 3
288+
}
289+
290+
It "-CNE:`$false should behave like default boolean evaluation" {
291+
# With -CNE:$false, the parameter is not specified, so default boolean evaluation applies
292+
$result = $testData | Where-Object Name -CNE:$false
293+
$result | Should -HaveCount 3
294+
}
295+
296+
It "-CGT:`$false should behave like default boolean evaluation" {
297+
# With -CGT:$false, the parameter is not specified, so default boolean evaluation applies
298+
$result = $testData | Where-Object Age -CGT:$false
299+
$result | Should -HaveCount 3
300+
}
301+
302+
It "-CLT:`$false should behave like default boolean evaluation" {
303+
# With -CLT:$false, the parameter is not specified, so default boolean evaluation applies
304+
$result = $testData | Where-Object Age -CLT:$false
305+
$result | Should -HaveCount 3
306+
}
307+
308+
It "-CGE:`$false should behave like default boolean evaluation" {
309+
# With -CGE:$false, the parameter is not specified, so default boolean evaluation applies
310+
$result = $testData | Where-Object Age -CGE:$false
311+
$result | Should -HaveCount 3
312+
}
313+
314+
It "-CLE:`$false should behave like default boolean evaluation" {
315+
# With -CLE:$false, the parameter is not specified, so default boolean evaluation applies
316+
$result = $testData | Where-Object Age -CLE:$false
317+
$result | Should -HaveCount 3
318+
}
319+
320+
It "-CLike:`$false should behave like default boolean evaluation" {
321+
# With -CLike:$false, the parameter is not specified, so default boolean evaluation applies
322+
$result = $testData | Where-Object City -CLike:$false
323+
$result | Should -HaveCount 3
324+
}
325+
326+
It "-CNotLike:`$false should behave like default boolean evaluation" {
327+
# With -CNotLike:$false, the parameter is not specified, so default boolean evaluation applies
328+
$result = $testData | Where-Object City -CNotLike:$false
329+
$result | Should -HaveCount 3
330+
}
331+
332+
It "-CMatch:`$false should behave like default boolean evaluation" {
333+
# With -CMatch:$false, the parameter is not specified, so default boolean evaluation applies
334+
$result = $testData | Where-Object Name -CMatch:$false
335+
$result | Should -HaveCount 3
336+
}
337+
338+
It "-CNotMatch:`$false should behave like default boolean evaluation" {
339+
# With -CNotMatch:$false, the parameter is not specified, so default boolean evaluation applies
340+
$result = $testData | Where-Object Name -CNotMatch:$false
341+
$result | Should -HaveCount 3
342+
}
343+
344+
It "-CContains:`$false should behave like default boolean evaluation" {
345+
# With -CContains:$false, the parameter is not specified, so default boolean evaluation applies
346+
$result = $testData | Where-Object Name -CContains:$false
347+
$result | Should -HaveCount 3
348+
}
349+
350+
It "-CNotContains:`$false should behave like default boolean evaluation" {
351+
# With -CNotContains:$false, the parameter is not specified, so default boolean evaluation applies
352+
$result = $testData | Where-Object Name -CNotContains:$false
353+
$result | Should -HaveCount 3
354+
}
355+
356+
It "-CIn:`$false should behave like default boolean evaluation" {
357+
# With -CIn:$false, the parameter is not specified, so default boolean evaluation applies
358+
$result = $testData | Where-Object Name -CIn:$false
359+
$result | Should -HaveCount 3
360+
}
361+
362+
It "-CNotIn:`$false should behave like default boolean evaluation" {
363+
# With -CNotIn:$false, the parameter is not specified, so default boolean evaluation applies
364+
$result = $testData | Where-Object Name -CNotIn:$false
365+
$result | Should -HaveCount 3
366+
}
367+
368+
It "-CEQ:`$false with -Value should throw an error requiring an operator" {
369+
# Similar behavior for -CEQ:$false with -Value
370+
{ $testData | Where-Object Name -CEQ:$false -Value 'Alice' } | Should -Throw -ErrorId 'OperatorNotSpecified,Microsoft.PowerShell.Commands.WhereObjectCommand'
371+
}
372+
373+
It "-CGT:`$false with -Value should throw an error requiring an operator" {
374+
# Similar behavior for -CGT:$false with -Value
375+
{ $testData | Where-Object Age -CGT:$false -Value 25 } | Should -Throw -ErrorId 'OperatorNotSpecified,Microsoft.PowerShell.Commands.WhereObjectCommand'
376+
}
377+
378+
It "-CLike:`$false with -Value should throw an error requiring an operator" {
379+
# Similar behavior for -CLike:$false with -Value
380+
{ $testData | Where-Object Name -CLike:$false -Value 'A*' } | Should -Throw -ErrorId 'OperatorNotSpecified,Microsoft.PowerShell.Commands.WhereObjectCommand'
381+
}
283382
}
284383
}

0 commit comments

Comments
 (0)