-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[e2e/command/autocomplete] Add autocomplete-posh-vcpkg.Test.ps1
- Loading branch information
1 parent
c9f4473
commit 5ff6ef7
Showing
2 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
180 changes: 180 additions & 0 deletions
180
azure-pipelines/end-to-end-tests-dir/autocomplete-posh-vcpkg.Test.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
BeforeAll { | ||
Import-Module $PSScriptRoot/../../scripts/posh-vcpkg.psd1 | ||
} | ||
|
||
Describe 'Module posh-vcpkg tests' { | ||
|
||
BeforeAll { | ||
|
||
function Complete-InputCaret { | ||
[OutputType([string[]])] | ||
param ( | ||
[Parameter(Mandatory, Position = 0, ValueFromPipeline)] | ||
[string]$caretCursorCommand | ||
) | ||
$positionMatches = [regex]::Matches($caretCursorCommand, '\^') | ||
if ($positionMatches.Count -ne 1) { | ||
throw 'Invalid caret cursor command, please indicate by only one ^ character' | ||
} | ||
$command = [string]$caretCursorCommand.Replace('^', '') | ||
$cursorPosition = [int]$positionMatches[0].Index | ||
$result = [System.Management.Automation.CommandCompletion]::CompleteInput($command, $cursorPosition, $null) | ||
# Write-Host ( $result.CompletionMatches | Select-Object -ExpandProperty CompletionText) | ||
return $result.CompletionMatches | Select-Object -ExpandProperty CompletionText | ||
} | ||
|
||
} | ||
|
||
Context 'Internal function tests' { | ||
|
||
It 'Complete-InputCaret 1 caret string should success' { | ||
'aaaa^' | Complete-InputCaret | Should -BeNullOrEmpty | ||
} | ||
|
||
It 'Complete-InputCaret 0 caret string should throw' { | ||
{ 'aaaa' | Complete-InputCaret } | Should -Throw | ||
} | ||
|
||
It 'Complete-InputCaret 2 caret string should throw' { | ||
{ 'aaaa^^' | Complete-InputCaret } | Should -Throw | ||
} | ||
|
||
It 'Complete-InputCaret self should success' { | ||
'Complete-InputCaret^' | Complete-InputCaret | Should -Contain 'Complete-InputCaret' | ||
} | ||
|
||
} | ||
|
||
Context 'Complete command name tests' { | ||
|
||
It 'Should complete command list with blank space [vcpkg ^] - <expected>' -ForEach ( | ||
@( | ||
, 'help' | ||
, 'install' | ||
, 'list' | ||
, 'remove' | ||
, 'version' | ||
) | ForEach-Object { @{Expected = $_ } } | ||
) { | ||
'vcpkg ^' | Complete-InputCaret | Should -Contain $expected | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
# Context 'Complete command name tests' { | ||
|
||
# It -Skip 'Should complete command list with blank space [<caretCmd>]' -TestCases ( | ||
# @{ caretCmd = 'vcpkg ^' ; expectedContain = 'version'; comment = 'without word' }, | ||
# @{ caretCmd = 'vcpkg ver^' ; expectedContain = 'version'; comment = 'with word' }, | ||
# @{ caretCmd = 'vcpkg.exe ver^' ; expectedContain = 'version'; comment = 'with native exe' }, | ||
# @{ caretCmd = './vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot slash' }, | ||
# @{ caretCmd = '.\vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot backslash' } | ||
# ) { | ||
# param($caretCmd, $expectedContain, $comment) | ||
# $caretCmd | Complete-InputCaret | Should -Contain $expectedContain | ||
# } | ||
|
||
# It -Skip 'Should complete command word [<expectedContain>] with [<caretCmd>] with <comment>' -TestCases ( | ||
# @{ caretCmd = 'vcpkg ^' ; expectedContain = 'version'; comment = 'without word' }, | ||
# @{ caretCmd = 'vcpkg ver^' ; expectedContain = 'version'; comment = 'with word' }, | ||
# @{ caretCmd = 'vcpkg.exe ver^' ; expectedContain = 'version'; comment = 'with native exe' }, | ||
# @{ caretCmd = './vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot slash' }, | ||
# @{ caretCmd = '.\vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot backslash' } | ||
# ) { | ||
# param($caretCmd, $expectedContain, $comment) | ||
# $caretCmd | Complete-InputCaret | Should -Contain $expectedContain | ||
# } | ||
|
||
# } | ||
|
||
# Context -Skip 'Complete command spaces tests' { | ||
|
||
# It 'Should complete command <comment> [<caretCmd>]' -TestCases ( | ||
# @{ comment = 'spaces without argument'; caretCmd = 'vcpkg ^'; expectedContain = 'version' }, | ||
# @{ comment = 'before remaining'; caretCmd = 'vcpkg ver^'; expectedContain = 'version' }, | ||
# # @{ comment = 'with trailing spaces'; caretCmd = 'vcpkg ver ^'; expectedContain = 'version' }, | ||
# @{ comment = 'with leading spaces'; caretCmd = ' vcpkg ver^'; expectedContain = 'version' } | ||
# ) { | ||
# param($caretCmd, $expectedContain, $comment) | ||
# $caretCmd | Complete-InputCaret | Should -Contain $expectedContain | ||
# } | ||
|
||
# It 'Should complete command with trailing spaces [vcpkg ver ^]' -Skip { | ||
# 'vcpkg ver ^' | Complete-InputCaret | Should -Contain 'version' | ||
# } | ||
|
||
# } | ||
|
||
# Context -Skip 'Complete command quotation tests' { | ||
|
||
# It "Should complete command with quoted word [vcpkg 'ver'^]" { | ||
# "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' | ||
# } | ||
|
||
# It "Should complete command with quoted space [vcpkg ' '^]" { | ||
# "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' | ||
# } | ||
|
||
# It "Should complete command with quoted word [vcpkg 'version'^]" { | ||
# "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' | ||
# } | ||
|
||
# } | ||
|
||
# Context -Skip 'Complete command intermediate tests' { | ||
|
||
# It 'Should complete command <comment> [<caretCmd>]' -TestCases ( | ||
# @{ comment = 'end of word'; caretCmd = 'vcpkg version^'; expectedContain = 'version' }, | ||
# @{ comment = 'middle of word'; caretCmd = 'vcpkg ver^sion'; expectedContain = 'version' }, | ||
# @{ comment = 'front of word'; caretCmd = 'vcpkg ^version'; expectedContain = 'version' } | ||
# ) { | ||
# param($caretCmd, $expectedContain, $comment) | ||
# $caretCmd | Complete-InputCaret | Should -Contain $expectedContain | ||
# } | ||
|
||
# } | ||
|
||
# Context -Skip 'Complete subcommand tests' { | ||
|
||
# It 'Should complete subcommand [<expected>] from [<caretCmd>]' -TestCases ( | ||
# @{ caretCmd = 'vcpkg depend^'; expected = 'depend-info' }, | ||
# @{ caretCmd = 'vcpkg inst^'; expected = 'install' }, | ||
# @{ caretCmd = 'vcpkg int^'; expected = 'integrate' }, | ||
# @{ caretCmd = 'vcpkg rem^'; expected = 'remove' } | ||
# ) { | ||
# param($caretCmd, $expected) | ||
# @($caretCmd | Complete-InputCaret)[0] | Should -BeExactly $expected | ||
# } | ||
|
||
# It 'Should complete subcommand two-level [powershell] from [vcpkg integrate power^]' -Skip { | ||
# 'vcpkg integrate power^' | Complete-InputCaret | Should -Contain 'powershell' | ||
# } | ||
|
||
# } | ||
|
||
# Context -Skip 'Complete subcommand argument and options tests' { | ||
|
||
# It 'Should complete argument [<expected>] from [<caretCmd>]' -TestCases ( | ||
# @{ caretCmd = 'vcpkg install vcpkg-cmake^'; expectedContain = 'vcpkg-cmake-get-vars' }, | ||
# @{ caretCmd = 'vcpkg install vcpkg-cmake --^'; expectedContain = '--dry-run' } | ||
# ) { | ||
# param($caretCmd, $expected) | ||
# $caretCmd | Complete-InputCaret | Should -Contain $expectedContain | ||
# } | ||
|
||
# } | ||
|
||
# Context -Skip 'Complete complex tests' { | ||
|
||
# It 'Should complete complex line [<expected>] from [<caretCmd>]' -TestCases ( | ||
# @{ caretCmd = 'echo powershell | % { vcpkg ver^ $_ }; echo $?'; expectedContain = 'version' } | ||
# ) { | ||
# param($caretCmd, $expected) | ||
# $caretCmd | Complete-InputCaret | Should -Contain $expectedContain | ||
# } | ||
|
||
# } | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
azure-pipelines/end-to-end-tests-dir/autocomplete-posh-z.Spec.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
Write-Host "It's spec." | ||
|
||
if ($IsLinux -or $IsWindows) { | ||
throw 'It is an error for end-to-end-tests.ps1 on Linux or Windows.' | ||
} |