MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Tab completion bug fix" -Tags "CI" {4 5 It "Issue#682 - '[system.manage<tab>' should work" {6 $result = TabExpansion2 -inputScript "[system.manage" -cursorColumn "[system.manage".Length7 $result.CompletionMatches | Should -HaveCount 18 $result.CompletionMatches[0].CompletionText | Should -BeExactly "System.Management"9 }10 11 It "Issue#1350 - '1 -sp<tab>' should work" {12 $result = TabExpansion2 -inputScript "1 -sp" -cursorColumn "1 -sp".Length13 $result.CompletionMatches | Should -HaveCount 114 $result.CompletionMatches[0].CompletionText | Should -BeExactly "-split"15 }16 17 It "Issue#1350 - '1 -a<tab>' should work" {18 $result = TabExpansion2 -inputScript "1 -a" -cursorColumn "1 -a".Length19 $result.CompletionMatches | Should -HaveCount 220 $result.CompletionMatches[0].CompletionText | Should -BeExactly "-and"21 $result.CompletionMatches[1].CompletionText | Should -BeExactly "-as"22 }23 It "Issue#2295 - '[pscu<tab>' should expand to [pscustomobject]" {24 $result = TabExpansion2 -inputScript "[pscu" -cursorColumn "[pscu".Length25 $result.CompletionMatches | Should -HaveCount 126 $result.CompletionMatches[0].CompletionText | Should -BeExactly "pscustomobject"27 }28 It "Issue#1345 - 'Import-Module -n<tab>' should work" {29 $cmd = "Import-Module -n"30 $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length31 $result.CompletionMatches | Should -HaveCount 232 $result.CompletionMatches[0].CompletionText | Should -BeExactly "-Name"33 $result.CompletionMatches[1].CompletionText | Should -BeExactly "-NoClobber"34 }35 36 It "Issue#11227 - [CompletionCompleters]::CompleteVariable and [CompletionCompleters]::CompleteType should work" {37 $result = [System.Management.Automation.CompletionCompleters]::CompleteType("CompletionComple")38 $result.Count | Should -BeExactly 139 $result[0].CompletionText | Should -BeExactly 'System.Management.Automation.CompletionCompleters'40 41 $result = [System.Management.Automation.CompletionCompleters]::CompleteVariable("errorAction")42 $result.Count | Should -BeExactly 143 $result[0].CompletionText | Should -BeExactly '$ErrorActionPreference'44 }45 46 It "Issue#24756 - Wildcard completions should not return early due to missing results in one container" -Skip:(!$IsWindows) {47 try48 {49 $keys = New-Item -Path @(50 'HKCU:\AB1'51 'HKCU:\AB2'52 'HKCU:\AB2\Test'53 )54 55 $res = TabExpansion2 -inputScript 'Get-ChildItem -Path HKCU:\AB?\'56 $res.CompletionMatches.Count | Should -Be 157 $res.CompletionMatches[0].CompletionText | Should -BeExactly "HKCU:\AB2\Test"58 }59 finally60 {61 if ($keys)62 {63 Remove-Item -Path HKCU:\AB? -Recurse -ErrorAction SilentlyContinue64 }65 }66 }67 68 Context "Issue#3416 - 'Select-Object'" {69 BeforeAll {70 $DatetimeProperties = @((Get-Date).psobject.baseobject.psobject.properties) | Sort-Object -Property Name71 }72 It "Issue#3416 - 'Select-Object -ExcludeProperty <tab>' should work" {73 $cmd = "Get-Date | Select-Object -ExcludeProperty "74 $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length75 $result.CompletionMatches | Should -HaveCount $DatetimeProperties.Count76 $result.CompletionMatches[0].CompletionText | Should -BeExactly $DatetimeProperties[0].Name # Date77 $result.CompletionMatches[1].CompletionText | Should -BeExactly $DatetimeProperties[1].Name # DateTime78 }79 It "Issue#3416 - 'Select-Object -ExpandProperty <tab>' should work" {80 $cmd = "Get-Date | Select-Object -ExpandProperty "81 $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length82 $result.CompletionMatches | Should -HaveCount $DatetimeProperties.Count83 $result.CompletionMatches[0].CompletionText | Should -BeExactly $DatetimeProperties[0].Name # Date84 $result.CompletionMatches[1].CompletionText | Should -BeExactly $DatetimeProperties[1].Name # DateTime85 }86 }87 88 It "Issue#3628 - 'Sort-Object @{<tab>' should work" {89 $cmd = "Get-Date | Sort-Object @{"90 $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length91 $result.CompletionMatches | Should -HaveCount 392 $result.CompletionMatches[0].CompletionText | Should -BeExactly 'Expression'93 $result.CompletionMatches[1].CompletionText | Should -BeExactly 'Ascending'94 $result.CompletionMatches[2].CompletionText | Should -BeExactly 'Descending'95 }96 97 It "'Get-Date | Sort-Object @{Expression=<tab>' should work without completion" {98 $cmd = "Get-Date | Sort-Object @{Expression="99 $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length100 $result.CompletionMatches | Should -HaveCount 0101 }102 103 It "Issue#5322 - 'Get-Date | Sort-Object @{Expression=...;' should work" {104 $cmd = "Get-Date | Sort-Object @{Expression=...;"105 $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length106 $result.CurrentMatchIndex | Should -Be -1107 $result.ReplacementIndex | Should -Be 40108 $result.ReplacementLength | Should -Be 0109 $result.CompletionMatches[0].CompletionText | Should -BeExactly 'Ascending'110 $result.CompletionMatches[1].CompletionText | Should -BeExactly 'Descending'111 }112 113 It "Issue#19912 - Tab completion should not crash" {114 $ISS = [initialsessionstate]::CreateDefault()115 $Runspace = [runspacefactory]::CreateRunspace($ISS)116 $Runspace.Open()117 $OldRunspace = [runspace]::DefaultRunspace118 try119 {120 [runspace]::DefaultRunspace = $Runspace121 {[System.Management.Automation.CommandCompletion]::CompleteInput('Get-', 3, $null)} | Should -Not -Throw122 }123 finally124 {125 [runspace]::DefaultRunspace = $OldRunspace126 $Runspace.Dispose()127 }128 }129 130 It "Issue#26277 - [CompletionCompleters]::CompleteFilename('') should work" {131 $testDir = Join-Path $TestDrive "TempTestDir"132 $file1 = Join-Path $testDir "abc.ps1"133 $file2 = Join-Path $testDir "def.py"134 135 New-Item -ItemType Directory -Path $testDir > $null136 New-Item -ItemType File -Path $file1 > $null137 New-Item -ItemType File -Path $file2 > $null138 139 try {140 Push-Location -Path $testDir141 $result = [System.Management.Automation.CompletionCompleters]::CompleteFilename("")142 $result | Should -Not -Be $null143 $result | Measure-Object | ForEach-Object -MemberName Count | Should -Be 2144 145 $item1, $item2 = @($result)146 $item1.ListItemText | Should -BeExactly 'abc.ps1'147 $item2.ListItemText | Should -BeExactly 'def.py'148 } finally {149 Pop-Location150 }151 }152}153 