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

Code before:
    }

    It 'Should include help resource message in parameter tool tip by direct match' {
        $expected = '`[string`] Activity - *'
        $Script = 'Write-Progress -Activity'
        $res = (TabExpansion2 -inputScript $Script).CompletionMatches
        $res.Count | Should -Be 1
        $res.CompletionText | Should -BeExactly '-Activity'
        $res.ToolTip | Should -BeLikeExactly $expected
    }

    It 'Should include help resource message in parameter tool tip by multiple matches' {
        $expected = '`[string`] Activity - *'
        $Script = 'Write-Progress -'
        $res = (TabExpansion2 -inputScript $Script).CompletionMatches | Where-Object CompletionText -eq '-Activity'
        $res.Count | Should -Be 1
        $res.CompletionText | Should -BeExactly '-Activity'
        $res.ToolTip | Should -BeLikeExactly $expected
    }
    
    It 'Should use first valid HelpMessage with multiple parameter attributes by direct match' {
        Function Test-Function {
            [CmdletBinding(DefaultParameterSetName = 'Default')]
            param (
                [Parameter(ParameterSetName = 'Foo', HelpMessage = 'Foo')]
                [Parameter(ParameterSetName = 'Default')]
                [string]
                $Param,
                
                [Parameter(ParameterSetName = 'Foo')]
                [switch]
                $Foo
            )
        }
        
        $expected = '[string] Param - Foo'
        $Script = 'Test-Function -Param'
        $res = (TabExpansion2 -inputScript $Script).CompletionMatches
        $res.Count | Should -Be 1
        $res.CompletionText | Should -BeExactly '-Param'
        $res.ToolTip | Should -BeExactly $expected
    }
    
    It 'Should use first valid HelpMessage with multiple parameter attributes by multiple match' {
        Function Test-Function {
            [CmdletBinding(DefaultParameterSetName = 'Default')]
            param (
                [Parameter(ParameterSetName = 'Foo', HelpMessage = 'Foo')]
                [Parameter(ParameterSetName = 'Default')]
                [string]
                $Param,

Review comment (suggestion):
I guess it should be:
```suggestion
                [Parameter(ParameterSetName = 'Foo', HelpMessage = 'Foo')]
                [Parameter(ParameterSetName = 'Default', HelpMessage = 'Second')]
```

Code after:
        $res = TabExpansion2 -inputScript $TestString
        $res.CompletionMatches[0].CompletionText | Should -BeExactly '$MyDataVar'
    }

    It 'Should complete global variable without scope' {
        $res = TabExpansion2 -inputScript '$Global:MyTestVar = "Hello";$MyTestV'
        $res.CompletionMatches[0].CompletionText | Should -BeExactly '$MyTestVar'
    }

    It 'Should complete previously assigned variable in using: scope' {
        $res = TabExpansion2 -inputScript '$MyTestVar = "Hello";$Using:MyTestv'
        $res.CompletionMatches[0].CompletionText | Should -BeExactly '$Using:MyTestVar'
    }

    it 'Should complete "Value" parameter value in "Where-Object" for Enum property with no input' {
        $res = TabExpansion2 -inputScript 'Get-Command | where-Object CommandType -eq '
        $res.CompletionMatches[0].CompletionText | Should -BeExactly Alias
    }

    it 'Should complete "Value" parameter value in "Where-Object" for Enum property with partial input' {
        $res = TabExpansion2 -inputScript 'Get-Command | where-Object CommandType -ne Ali'
        $res.CompletionMatches[0].CompletionText | Should -BeExactly Alias
    }

    it 'Should complete the right hand side of a comparison operator when left is an Enum with no input' {
        $res = TabExpansion2 -inputScript 'Get-Command | Where-Object -FilterScript {$_.CommandType -like '
        $res.CompletionMatches[0].CompletionText | Should -BeExactly "'Alias'"
    }

    it 'Should complete the right hand side of a comparison operator when left is an Enum with partial input' {
        $TempVar = Get-Command
        $res = TabExpansion2 -inputScript '$tempVar[0].CommandType -notlike "Ali"'
        $res.CompletionMatches[0].CompletionText | Should -BeExactly "'Alias'"
    }

    it 'Should complete the right hand side of a comparison operator when left is an Enum when cursor is on a newline' {
        $res = TabExpansion2 -inputScript "Get-Command | Where-Object -FilterScript {`$_.CommandType -like`n"
        $res.CompletionMatches[0].CompletionText | Should -BeExactly "'Alias'"
    }

    it 'Should complete provider dynamic parameters with quoted path' {
        $Script = if ($IsWindows)
        {
            'Get-ChildItem -Path "C:\" -Director'
        }
        else
        {
            'Get-ChildItem -Path "/" -Director'
        }
        $res = TabExpansion2 -inputScript $Script
        $res.CompletionMatches[0].CompletionText | Should -BeExactly '-Directory'