Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ Describe "TabCompletion" -Tags CI {
}

It 'Should complete abbreviated cmdlet' {
$res = pwsh -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText"
$res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText"
$res | Should -HaveCount 1
$res | Should -BeExactly 'Import-PowerShellDataFile'
}

It 'Should complete abbreviated function' {
$res = pwsh -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText"
$res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText"
$res.Count | Should -BeGreaterOrEqual 1
$res | Should -BeExactly 'PSConsoleHostReadLine'
}
Expand Down Expand Up @@ -245,6 +245,51 @@ Describe "TabCompletion" -Tags CI {
$completionText -join ' '| Should -BeExactly 'blg csv tsv'
}

Context "Script name completion" {
BeforeAll {
setup -f 'install-powershell.ps1' -content ""
setup -f 'remove-powershell.ps1' -content ""

$scriptWithWildcardCases = @(
@{
command = '.\install-*.ps1'
expectedCommand = Join-Path -Path '.' -ChildPath 'install-powershell.ps1'
name = "'$(Join-Path -Path '.' -ChildPath 'install-powershell.ps1')'"
}
@{
command = (Join-Path ${TestDrive} -ChildPath 'install-*.ps1')
expectedCommand = (Join-Path ${TestDrive} -ChildPath 'install-powershell.ps1')
name = "'$(Join-Path -Path '.' -ChildPath 'install-powershell.ps1')' by fully qualified path"
}
@{
command = '.\?emove-powershell.ps1'
expectedCommand = Join-Path -Path '.' -ChildPath 'remove-powershell.ps1'
name = "'$(Join-Path -Path '.' -ChildPath '?emove-powershell.ps1')'"
}
@{
# [] cause the parser to create a new token.
# So, the command must be quoted to tab complete.
command = "'.\[ra]emove-powershell.ps1'"
expectedCommand = "'$(Join-Path -Path '.' -ChildPath 'remove-powershell.ps1')'"
name = "'$(Join-Path -Path '.' -ChildPath '[ra]emove-powershell.ps1')'"
}
)

Push-Location ${TestDrive}\
}

AfterAll {
Pop-Location
}

it "Input <name> should successfully complete" -TestCases $scriptWithWildcardCases {
param($command, $expectedCommand)
$res = TabExpansion2 -inputScript $command -cursorColumn $command.Length
$res.CompletionMatches.Count | Should -BeGreaterThan 0
$res.CompletionMatches[0].CompletionText | Should -BeExactly $expectedCommand
}
}

Context "File name completion" {
BeforeAll {
$tempDir = Join-Path -Path $TestDrive -ChildPath "baseDir"
Expand Down
29 changes: 29 additions & 0 deletions test/powershell/engine/Basic/CommandDiscovery.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,33 @@ Describe "Command Discovery tests" -Tags "CI" {
It "Get- is prepended to commands" {
(& 'location').Path | Should -Be (get-location).Path
}

Context "Get-Command should use globbing for scripts" {
BeforeAll {
$firstResult = '[first script]'
$secondResult = 'alt script'
setup -f '[test1].ps1' -content "'$firstResult'"
setup -f '1.ps1' -content "'$secondResult'"

$gcmWithWildcardCases = @(
@{command = '.\?[tb]est1?.ps1'; expectedCommand = '[test1].ps1'; expectedCommandCount =1; name = '''.\?[tb]est1?.ps1'''}
@{command = (Join-Path ${TestDrive} -ChildPath '?[tb]est1?.ps1'); expectedCommand = '[test1].ps1'; expectedCommandCount =1 ; name = '''.\?[tb]est1?.ps1'' by fully qualified path'}
@{command = '.\[test1].ps1'; expectedCommand = '1.ps1'; expectedCommandCount =1; name = '''.\[test1].ps1'''}
@{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1'); expectedCommand = '1.ps1'; expectedCommandCount =1 ; name = '''.\[test1].ps1'' by fully qualified path'}
)

Push-Location ${TestDrive}\
Comment thread
TravisEz13 marked this conversation as resolved.
Resolved
}

AfterAll {
Pop-Location
}

It "Get-Command <name> should return <expectedCommandCount> command named '<expectedCommand>'" -TestCases $gcmWithWildcardCases {
param($command, $expectedCommand, $expectedCommandCount)
$commands = Get-Command -Name $command
$commands.Count | Should -Be $expectedCommandCount
$commands.Name | Should -BeExactly $expectedCommand
}
}
}