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

Code before:

    It 'Should have type and name for parameter without help message' {
        Function Test-Function {
            param (
                [Parameter()]
                $WithAttribute,

                $WithoutAttribute
            )
        }

        $Script = 'Test-Function -'
        $res = (TabExpansion2 -inputScript $Script).CompletionMatches |
            Where-Object CompletionText -in '-WithAttribute', '-WithoutAttribute' |
            Sort-Object CompletionText
        $res.Count | Should -Be 2

        $res.CompletionText[0] | Should -BeExactly '-WithAttribute'
        $res.ToolTip[0] | Should -BeExactly '[Object] WithAttribute'

        $res.CompletionText[1] | Should -BeExactly '-WithoutAttribute'
        $res.ToolTip[1] | Should -BeExactly '[Object] WithoutAttribute'
    }

    It 'Should include help resource message in parameter tool tip by direct match' {
        $expected = '[string] Activity - Text to describe the activity for which progress is being reported.'
        $Script = 'Write-Progress -Activity'
        $res = (TabExpansion2 -inputScript $Script).CompletionMatches
        $res.Count | Should -Be 1
        $res.CompletionText | Should -BeExactly '-Activity'
        $res.ToolTip | Should -BeExactly $expected
    }

    It 'Should include help resource message in parameter tool tip by multiple matches' {
        $expected = '[string] Activity - Text to describe the activity for which progress is being reported.'
        $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 -BeExactly $expected
    }

    Context 'Start-Process -Verb parameter completion' {
        BeforeAll {
            function GetProcessInfoVerbs([string]$path, [switch]$singleQuote, [switch]$doubleQuote) {
                $verbs = (New-Object -TypeName System.Diagnostics.ProcessStartInfo -ArgumentList $path).Verbs

                if ($singleQuote) {
                    return ($verbs | ForEach-Object { "'$_'" })
                }
                elseif ($doubleQuote) {

Review comment (suggestion):
We can not use a string in tests if it comes from localized resources.
I suggest to check that a string _present_ after `-Activity` in the result but not check it exactly.

Code after:
        $Expected = ([ValidatePattern].GetProperties() | Where-Object {$_.CanWrite}).Name -join ','
        $res.CompletionMatches.CompletionText -join ',' | Should -BeExactly $Expected
    }

    It 'Should complete argument for second parameter' {
        $res = TabExpansion2 -inputScript 'Get-ChildItem -Path $HOME -ErrorAction '
        $res.CompletionMatches[0].CompletionText | Should -BeExactly Break
    }

    It 'Should complete argument with validateset attribute after comma' {
        $TestString = 'function Test-ValidateSet{Param([ValidateSet("Cat","Dog")]$Param1,$Param2)};Test-ValidateSet -Param1 Dog, -Param2'
        $res = TabExpansion2 -inputScript $TestString -cursorColumn ($TestString.LastIndexOf(',') + 1)
        $res.CompletionMatches[0].CompletionText | Should -BeExactly Cat
    }

    It 'Should complete cim ETS member added by shortname' -Skip:(!$IsWindows -or (Test-IsWinServer2012R2) -or (Test-IsWindows2016)) {
        $res = TabExpansion2 -inputScript '(Get-NetFirewallRule).Nam'
        $res.CompletionMatches[0].CompletionText | Should -BeExactly 'Name'
    }

    It 'Should complete variable assigned with Data statement' {
        $TestString = 'data MyDataVar {"Hello"};$MyDatav'
        $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'"
    }