8000 manual merge of TabCompletion.Tests.ps1 · PowerShell/PowerShell@2727ca9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2727ca9

Browse files
author
Staffan Gustafsson
committed
manual merge of TabCompletion.Tests.ps1
1 parent 3024cd6 commit 2727ca9

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
Describe "TabCompletion" -Tags CI {
2+
It 'Should complete Command' {
3+
$res = TabExpansion2 -inputScript 'Get-Com' -cursorColumn 'Get-Com'.Length
4+
$res.CompletionMatches[0].CompletionText | Should be Get-Command
5+
}
6+
7+
It 'Should complete native exe' -Skip:(!$IsWindows) {
8+
$res = TabExpansion2 -inputScript 'notep' -cursorColumn 'notep'.Length
9+
$res.CompletionMatches[0].CompletionText | Should Be notepad.exe
10+
}
11+
12+
It 'Should complete dotnet method' {
13+
$res = TabExpansion2 -inputScript '(1).ToSt' -cursorColumn '(1).ToSt'.Length
14+
$res.CompletionMatches[0].CompletionText | Should Be 'ToString('
15+
}
16+
17+
It 'Should complete Magic foreach' {
18+
$res = TabExpansion2 -inputScript '(1..10).Fo' -cursorColumn '(1..10).Fo'.Length
19+
$res.CompletionMatches[0].CompletionText | Should Be 'Foreach('
20+
}
21+
22+
It 'Should complete types' {
23+
$res = TabExpansion2 -inputScript '[pscu' -cursorColumn '[pscu'.Length
24+
$res.CompletionMatches[0].CompletionText | Should Be 'pscustomobject'
25+
}
26+
27+
It 'Should complete namespaces' {
28+
$res = TabExpansion2 -inputScript 'using namespace Sys' -cursorColumn 'using namespace Sys'.Length
29+
$res.CompletionMatches[0].CompletionText | Should Be 'System'
30+
}
31+
32+
It 'Should complete format-table hashtable' {
33+
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Table @{ ' -cursorColumn 'Get-ChildItem | Format-Table @{ '.Length
34+
$res.CompletionMatches.Count | Should Be 5
35+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Label', 'Width', 'Alignment', 'Expression', 'FormatString' | Should Be $true}
36+
}
37+
38+
39+
It 'Should complete format-* hashtable on GroupBy' -TestCases (
40+
@{cmd = 'Format-Table'},
41+
@{cmd = 'Format-List'},
42+
@{cmd = 'Format-Wide'},
43+
@{cmd = 'Format-Custom'}
44+
) {
45+
param($cmd)
46+
$res = TabExpansion2 -inputScript "Get-ChildItem | $cmd -GroupBy @{ " -cursorColumn "Get-ChildItem | $cmd -GroupBy @{ ".Length
47+
$res.CompletionMatches.Count | Should Be 3
48+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Label', 'Expression', 'FormatString' | Should Be $true}
49+
}
50+
51+
It 'Should complete format-list hashtable' {
52+
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-List @{ ' -cursorColumn 'Get-ChildItem | Format-List @{ '.Length
53+
$res.CompletionMatches.Count | Should Be 3
54+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Label', 'Expression', 'FormatString' | Should Be $true}
55+
}
56+
57+
It 'Should complete format-wide hashtable' {
58+
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Wide @{ ' -cursorColumn 'Get-ChildItem | Format-Wide @{ '.Length
59+
$res.CompletionMatches.Count | Should Be 2
60+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Expression', 'FormatString' | Should Be $true}
61+
}
62+
63+
It 'Should complete format-custom hashtable' {
64+
$res = TabExpansion2 -inputScript 'Get-ChildItem | Format-Custom @{ ' -cursorColumn 'Get-ChildItem | Format-Custom @{ '.Length
65+
$res.CompletionMatches.Count | Should Be 2
66+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Expression', 'Depth' | Should Be $true}
67+
}
68+
69+
It 'Should complete Select-Object hashtable' {
70+
$res = TabExpansion2 -inputScript 'Get-ChildItem | Select-Object @{ ' -cursorColumn 'Get-ChildItem | Select-Object @{ '.Length
71+
$res.CompletionMatches.Count | Should Be 2
72+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Name', 'Expression' | Should Be $true}
73+
}
74+
75+
It 'Should complete Sort-Object hashtable' {
76+
$res = TabExpansion2 -inputScript 'Get-ChildItem | Sort-Object @{ ' -cursorColumn 'Get-ChildItem | Sort-Object @{ '.Length
77+
$res.CompletionMatches.Count | Should Be 3
78+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'Expression', 'Ascending', 'Descending' | Should Be $true}
79+
}
80+
81+
It 'Should complete New-Object hashtable' {
82+
class X {
83+
$A
84+
$B
85+
$C
86+
}
87+
$res = TabExpansion2 -inputScript 'New-Object -TypeName X -Property @{ ' -cursorColumn 'New-Object -TypeName X -Property @{ '.Length
88+
$res.CompletionMatches.Count | Should Be 3
89+
$res.CompletionMatches.Foreach{$_.CompletionText -in 'A', 'B', 'C' | Should Be $true}
90+
}
91+
92+
It 'Should complete keyword' -skip {
93+
$res = TabExpansion2 -inputScript 'using nam' -cursorColumn 'using nam'.Length
94+
$res.CompletionMatches[0].CompletionText | Should Be 'namespace'
95+
}
96+
97+
Context NativeCommand {
98+
BeforeAll {
99+
$nativeCommand = (Get-Command -CommandType Application -TotalCount 1).Name
100+
}
101+
It 'Completes native commands with -' {
102+
Register-ArgumentCompleter -Native -CommandName $nativeCommand -ScriptBlock {
103+
param($wordToComplete, $ast, $cursorColumn)
104+
if ($wordToComplete -eq '-') {
105+
return "-flag"
106+
}
107+
else {
108+
return "unexpected wordtocomplete"
109+
}
110+
}
111+
$line = "$nativeCommand -"
112+
$res = TabExpansion2 -inputScript $line -cursorColumn $line.Length
113+
$res.CompletionMatches.Count | Should Be 1
114+
$res.CompletionMatches.CompletionText | Should Be "-flag"
115+
}
116+
117+
It 'Completes native commands with --' {
118+
Register-ArgumentCompleter -Native -CommandName $nativeCommand -ScriptBlock {
119+
param($wordToComplete, $ast, $cursorColumn)
120+
if ($wordToComplete -eq '--') {
121+
return "--flag"
122+
}
123+
else {
124+
return "unexpected wordtocomplete"
125+
}
126+
}
127+
$line = "$nativeCommand --"
128+
$res = TabExpansion2 -inputScript $line -cursorColumn $line.Length
129+
$res.CompletionMatches.Count | Should Be 1
130+
$res.CompletionMatches.CompletionText | Should Be "--flag"
131+
}
132+
133+
It 'Completes native commands with --f' {
134+
Register-ArgumentCompleter -Native -CommandName $nativeCommand -ScriptBlock {
135+
param($wordToComplete, $ast, $cursorColumn)
136+
if ($wordToComplete -eq '--f') {
137+
return "--flag"
138+
}
139+
else {
140+
return "unexpected wordtocomplete"
141+
}
142+
}
143+
$line = "$nativeCommand --f"
144+
$res = TaBexpansion2 -inputScript $line -cursorColumn $line.Length
145+
$res.CompletionMatches.Count | Should Be 1
146+
$res.CompletionMatches.CompletionText | Should Be "--flag"
147+
}
148+
149+
It 'Completes native commands with -o' {
150+
Register-ArgumentCompleter -Native -CommandName $nativeCommand -ScriptBlock {
151+
param($wordToComplete, $ast, $cursorColumn)
152+
if ($wordToComplete -eq '-o') {
153+
return "-option"
154+
}
155+
else {
156+
return "unexpected wordtocomplete"
157+
}
158+
}
159+
$line = "$nativeCommand -o"
160+
$res = TaBexpansion2 -inputScript $line -cursorColumn $line.Length
161+
$res.CompletionMatches.Count | Should Be 1
162+
$res.CompletionMatches.CompletionText | Should Be "-option"
163+
}
164+
}
165+
}

0 commit comments

Comments
 (0)
0