Repository: PowerShell/PowerShell
File: test/powershell/Host/TabCompletion/BugFix.Tests.ps1 (PowerShell)

Code before:
        $result.Count | Should -BeExactly 1
        $result[0].CompletionText | Should -BeExactly 'System.Management.Automation.CompletionCompleters'

        $result = [System.Management.Automation.CompletionCompleters]::CompleteVariable("errorAction")
        $result.Count | Should -BeExactly 1
        $result[0].CompletionText | Should -BeExactly '$ErrorActionPreference'
    }

    It "Issue#24756 - Wildcard completions should not return early due to missing results in one container" -Skip:(!$IsWindows) {
        try
        {
            $keys = New-Item -Path @(
                'HKCU:\AB1'
                'HKCU:\AB2'
                'HKCU:\AB2\Test'
            )

            $res = TabExpansion2 -inputScript 'Get-ChildItem -Path HKCU:\AB?\'
            $res.CompletionMatches.Count | Should -Be 1
            $res.CompletionMatches[0].CompletionText | Should -BeExactly "HKCU:\AB2\Test"
        }
        finally
        {
            if ($keys)
            {
                Remove-Item -Path HKCU:\AB? -Recurse
            }
        }
    }

    Context "Issue#3416 - 'Select-Object'" {
        BeforeAll {
            $DatetimeProperties = @((Get-Date).psobject.baseobject.psobject.properties) | Sort-Object -Property Name
        }
        It "Issue#3416 - 'Select-Object -ExcludeProperty <tab>' should work" {
            $cmd = "Get-Date | Select-Object -ExcludeProperty "
            $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
            $result.CompletionMatches | Should -HaveCount $DatetimeProperties.Count
            $result.CompletionMatches[0].CompletionText | Should -BeExactly $DatetimeProperties[0].Name # Date
            $result.CompletionMatches[1].CompletionText | Should -BeExactly $DatetimeProperties[1].Name # DateTime
       }
       It "Issue#3416 - 'Select-Object -ExpandProperty <tab>' should work" {
           $cmd = "Get-Date | Select-Object -ExpandProperty "
           $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
           $result.CompletionMatches | Should -HaveCount $DatetimeProperties.Count
           $result.CompletionMatches[0].CompletionText | Should -BeExactly $DatetimeProperties[0].Name # Date
           $result.CompletionMatches[1].CompletionText | Should -BeExactly $DatetimeProperties[1].Name # DateTime
       }
    }

    It "Issue#3628 - 'Sort-Object @{<tab>' should work" {

Review comment (suggestion):
```suggestion
                Remove-Item -Path HKCU:\AB? -Recurse -ErrorAction SilentlyContinue
```

Code after:
        $result.Count | Should -BeExactly 1
        $result[0].CompletionText | Should -BeExactly 'System.Management.Automation.CompletionCompleters'

        $result = [System.Management.Automation.CompletionCompleters]::CompleteVariable("errorAction")
        $result.Count | Should -BeExactly 1
        $result[0].CompletionText | Should -BeExactly '$ErrorActionPreference'
    }

    It "Issue#24756 - Wildcard completions should not return early due to missing results in one container" -Skip:(!$IsWindows) {
        try
        {
            $keys = New-Item -Path @(
                'HKCU:\AB1'
                'HKCU:\AB2'
                'HKCU:\AB2\Test'
            )

            $res = TabExpansion2 -inputScript 'Get-ChildItem -Path HKCU:\AB?\'
            $res.CompletionMatches.Count | Should -Be 1
            $res.CompletionMatches[0].CompletionText | Should -BeExactly "HKCU:\AB2\Test"
        }
        finally
        {
            if ($keys)
            {
                Remove-Item -Path HKCU:\AB? -Recurse -ErrorAction SilentlyContinue
            }
        }
    }

    Context "Issue#3416 - 'Select-Object'" {
        BeforeAll {
            $DatetimeProperties = @((Get-Date).psobject.baseobject.psobject.properties) | Sort-Object -Property Name
        }
        It "Issue#3416 - 'Select-Object -ExcludeProperty <tab>' should work" {
            $cmd = "Get-Date | Select-Object -ExcludeProperty "
            $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
            $result.CompletionMatches | Should -HaveCount $DatetimeProperties.Count
            $result.CompletionMatches[0].CompletionText | Should -BeExactly $DatetimeProperties[0].Name # Date
            $result.CompletionMatches[1].CompletionText | Should -BeExactly $DatetimeProperties[1].Name # DateTime
       }
       It "Issue#3416 - 'Select-Object -ExpandProperty <tab>' should work" {
           $cmd = "Get-Date | Select-Object -ExpandProperty "
           $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
           $result.CompletionMatches | Should -HaveCount $DatetimeProperties.Count
           $result.CompletionMatches[0].CompletionText | Should -BeExactly $DatetimeProperties[0].Name # Date
           $result.CompletionMatches[1].CompletionText | Should -BeExactly $DatetimeProperties[1].Name # DateTime
       }
    }

    It "Issue#3628 - 'Sort-Object @{<tab>' should work" {