Repository: PowerShell/PowerShell
File: test/powershell/Modules/Microsoft.PowerShell.Core/Where-Object.Tests.ps1 (PowerShell)

Code before:
    It 'Where-Object should handle dynamic (DLR) objects' {
        $dynObj = [TestDynamic]::new()
        $Result = $dynObj, $dynObj | Where-Object FooProp -EQ 123
        $Result | Should -HaveCount 2
        $Result[0] | Should -Be $dynObj
        $Result[1] | Should -Be $dynObj
    }

    It 'Where-Object should handle dynamic (DLR) objects, even without property name hint' {
        $dynObj = [TestDynamic]::new()
        $Result = $dynObj, $dynObj | Where-Object HiddenProp -EQ 789
        $Result | Should -HaveCount 2
        $Result[0] | Should -Be $dynObj
        $Result[1] | Should -Be $dynObj
    }

    Context "Switch parameter explicit $false handling" {
        BeforeAll {
            $testData = @(
                [PSCustomObject]@{ Name = 'Alice'; Age = 25; City = 'New York' }
                [PSCustomObject]@{ Name = 'Bob'; Age = 30; City = 'Boston' }
                [PSCustomObject]@{ Name = 'Charlie'; Age = 35; City = 'Chicago' }
            )
        }

        It "-EQ:$false should behave like default boolean evaluation" {
            # With -EQ:False, the parameter is not specified, so default boolean evaluation applies
            # "... | Where-Object Name" is equivalent to "... | Where-Object {$true -eq $_.Name}"
            # Non-empty strings are truthy
            $result = $testData | Where-Object Name -EQ:$false
            $result | Should -HaveCount 3
        }

        It "-GT:$false should behave like default boolean evaluation" {
            # With -GT:False, the parameter is not specified, so default boolean evaluation applies
            $result = $testData | Where-Object Age -GT:$false
            $result | Should -HaveCount 3
        }

        It "-Like:$false should behave like default boolean evaluation" {
            # With -Like:False, the parameter is not specified, so default boolean evaluation applies
            $result = $testData | Where-Object City -Like:$false
            $result | Should -HaveCount 3
        }

        It "-Match:$false should behave like default boolean evaluation" {
            # With -Match:False, the parameter is not specified, so default boolean evaluation applies
            $result = $testData | Where-Object Name -Match:$false
            $result | Should -HaveCount 3
        }


Review comment (security):
I think we need to escape $ in all test headers.
```suggestion
        It "-EQ:`$false should behave like default boolean evaluation" {
```

Code after:
    It 'Where-Object should handle dynamic (DLR) objects' {
        $dynObj = [TestDynamic]::new()
        $Result = $dynObj, $dynObj | Where-Object FooProp -EQ 123
        $Result | Should -HaveCount 2
        $Result[0] | Should -Be $dynObj
        $Result[1] | Should -Be $dynObj
    }

    It 'Where-Object should handle dynamic (DLR) objects, even without property name hint' {
        $dynObj = [TestDynamic]::new()
        $Result = $dynObj, $dynObj | Where-Object HiddenProp -EQ 789
        $Result | Should -HaveCount 2
        $Result[0] | Should -Be $dynObj
        $Result[1] | Should -Be $dynObj
    }

    Context "Switch parameter explicit `$false handling" {
        BeforeAll {
            $testData = @(
                [PSCustomObject]@{ Name = 'Alice'; Age = 25; City = 'New York' }
                [PSCustomObject]@{ Name = 'Bob'; Age = 30; City = 'Boston' }
                [PSCustomObject]@{ Name = 'Charlie'; Age = 35; City = 'Chicago' }
            )
        }

        It "-EQ:`$false should behave like default boolean evaluation" {
            # With -EQ:$false, the parameter is not specified, so default boolean evaluation applies
            # "... | Where-Object Name" is equivalent to "... | Where-Object {$true -eq $_.Name}"
            # Non-empty strings are truthy
            $result = $testData | Where-Object Name -EQ:$false
            $result | Should -HaveCount 3
        }

        It "-GT:`$false should behave like default boolean evaluation" {
            # With -GT:$false, the parameter is not specified, so default boolean evaluation applies
            $result = $testData | Where-Object Age -GT:$false
            $result | Should -HaveCount 3
        }

        It "-LT:`$false should behave like default boolean evaluation" {
            # With -LT:$false, the parameter is not specified, so default boolean evaluation applies
            $result = $testData | Where-Object Age -LT:$false
            $result | Should -HaveCount 3
        }

        It "-NE:`$false should behave like default boolean evaluation" {
            # With -NE:$false, the parameter is not specified, so default boolean evaluation applies
            $result = $testData | Where-Object Name -NE:$false
            $result | Should -HaveCount 3
        }