|
| 1 | +BeforeAll { |
| 2 | + Import-Module $PSScriptRoot/../../scripts/posh-vcpkg.psd1 |
| 3 | +} |
| 4 | + |
| 5 | +Describe 'Module posh-vcpkg tests' { |
| 6 | + |
| 7 | + BeforeAll { |
| 8 | + |
| 9 | + function Complete-InputCaret { |
| 10 | + [OutputType([string[]])] |
| 11 | + param ( |
| 12 | + [Parameter(Mandatory, Position = 0, ValueFromPipeline)] |
| 13 | + [string]$caretCursorCommand |
| 14 | + ) |
| 15 | + $positionMatches = [regex]::Matches($caretCursorCommand, '\^') |
| 16 | + if ($positionMatches.Count -ne 1) { |
| 17 | + throw 'Invalid caret cursor command, please indicate by only one ^ character' |
| 18 | + } |
| 19 | + $command = [string]$caretCursorCommand.Replace('^', '') |
| 20 | + $cursorPosition = [int]$positionMatches[0].Index |
| 21 | + $result = [System.Management.Automation.CommandCompletion]::CompleteInput($command, $cursorPosition, $null) |
| 22 | + # Write-Host ( $result.CompletionMatches | Select-Object -ExpandProperty CompletionText) |
| 23 | + return $result.CompletionMatches | Select-Object -ExpandProperty CompletionText |
| 24 | + } |
| 25 | + |
| 26 | + } |
| 27 | + |
| 28 | + Context 'Internal function tests' { |
| 29 | + |
| 30 | + It 'Complete-InputCaret 1 caret string should success' { |
| 31 | + 'aaaa^' | Complete-InputCaret | Should -BeNullOrEmpty |
| 32 | + } |
| 33 | + |
| 34 | + It 'Complete-InputCaret 0 caret string should throw' { |
| 35 | + { 'aaaa' | Complete-InputCaret } | Should -Throw |
| 36 | + } |
| 37 | + |
| 38 | + It 'Complete-InputCaret 2 caret string should throw' { |
| 39 | + { 'aaaa^^' | Complete-InputCaret } | Should -Throw |
| 40 | + } |
| 41 | + |
| 42 | + It 'Complete-InputCaret self should success' { |
| 43 | + 'Complete-InputCaret^' | Complete-InputCaret | Should -Contain 'Complete-InputCaret' |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + |
| 48 | + Context 'Complete command name tests' { |
| 49 | + |
| 50 | + It 'Should complete command list with blank space [vcpkg ^] - <expected>' -ForEach ( |
| 51 | + @( |
| 52 | + , 'help' |
| 53 | + , 'install' |
| 54 | + , 'list' |
| 55 | + , 'remove' |
| 56 | + , 'version' |
| 57 | + ) | ForEach-Object { @{Expected = $_ } } |
| 58 | + ) { |
| 59 | + 'vcpkg ^' | Complete-InputCaret | Should -Contain $expected |
| 60 | + } |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + # Context 'Complete command name tests' { |
| 67 | + |
| 68 | + # It -Skip 'Should complete command list with blank space [<caretCmd>]' -TestCases ( |
| 69 | + # @{ caretCmd = 'vcpkg ^' ; expectedContain = 'version'; comment = 'without word' }, |
| 70 | + # @{ caretCmd = 'vcpkg ver^' ; expectedContain = 'version'; comment = 'with word' }, |
| 71 | + # @{ caretCmd = 'vcpkg.exe ver^' ; expectedContain = 'version'; comment = 'with native exe' }, |
| 72 | + # @{ caretCmd = './vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot slash' }, |
| 73 | + # @{ caretCmd = '.\vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot backslash' } |
| 74 | + # ) { |
| 75 | + # param($caretCmd, $expectedContain, $comment) |
| 76 | + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain |
| 77 | + # } |
| 78 | + |
| 79 | + # It -Skip 'Should complete command word [<expectedContain>] with [<caretCmd>] with <comment>' -TestCases ( |
| 80 | + # @{ caretCmd = 'vcpkg ^' ; expectedContain = 'version'; comment = 'without word' }, |
| 81 | + # @{ caretCmd = 'vcpkg ver^' ; expectedContain = 'version'; comment = 'with word' }, |
| 82 | + # @{ caretCmd = 'vcpkg.exe ver^' ; expectedContain = 'version'; comment = 'with native exe' }, |
| 83 | + # @{ caretCmd = './vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot slash' }, |
| 84 | + # @{ caretCmd = '.\vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot backslash' } |
| 85 | + # ) { |
| 86 | + # param($caretCmd, $expectedContain, $comment) |
| 87 | + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain |
| 88 | + # } |
| 89 | + |
| 90 | + # } |
| 91 | + |
| 92 | + # Context -Skip 'Complete command spaces tests' { |
| 93 | + |
| 94 | + # It 'Should complete command <comment> [<caretCmd>]' -TestCases ( |
| 95 | + # @{ comment = 'spaces without argument'; caretCmd = 'vcpkg ^'; expectedContain = 'version' }, |
| 96 | + # @{ comment = 'before remaining'; caretCmd = 'vcpkg ver^'; expectedContain = 'version' }, |
| 97 | + # # @{ comment = 'with trailing spaces'; caretCmd = 'vcpkg ver ^'; expectedContain = 'version' }, |
| 98 | + # @{ comment = 'with leading spaces'; caretCmd = ' vcpkg ver^'; expectedContain = 'version' } |
| 99 | + # ) { |
| 100 | + # param($caretCmd, $expectedContain, $comment) |
| 101 | + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain |
| 102 | + # } |
| 103 | + |
| 104 | + # It 'Should complete command with trailing spaces [vcpkg ver ^]' -Skip { |
| 105 | + # 'vcpkg ver ^' | Complete-InputCaret | Should -Contain 'version' |
| 106 | + # } |
| 107 | + |
| 108 | + # } |
| 109 | + |
| 110 | + # Context -Skip 'Complete command quotation tests' { |
| 111 | + |
| 112 | + # It "Should complete command with quoted word [vcpkg 'ver'^]" { |
| 113 | + # "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' |
| 114 | + # } |
| 115 | + |
| 116 | + # It "Should complete command with quoted space [vcpkg ' '^]" { |
| 117 | + # "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' |
| 118 | + # } |
| 119 | + |
| 120 | + # It "Should complete command with quoted word [vcpkg 'version'^]" { |
| 121 | + # "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' |
| 122 | + # } |
| 123 | + |
| 124 | + # } |
| 125 | + |
| 126 | + # Context -Skip 'Complete command intermediate tests' { |
| 127 | + |
| 128 | + # It 'Should complete command <comment> [<caretCmd>]' -TestCases ( |
| 129 | + # @{ comment = 'end of word'; caretCmd = 'vcpkg version^'; expectedContain = 'version' }, |
| 130 | + # @{ comment = 'middle of word'; caretCmd = 'vcpkg ver^sion'; expectedContain = 'version' }, |
| 131 | + # @{ comment = 'front of word'; caretCmd = 'vcpkg ^version'; expectedContain = 'version' } |
| 132 | + # ) { |
| 133 | + # param($caretCmd, $expectedContain, $comment) |
| 134 | + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain |
| 135 | + # } |
| 136 | + |
| 137 | + # } |
| 138 | + |
| 139 | + # Context -Skip 'Complete subcommand tests' { |
| 140 | + |
| 141 | + # It 'Should complete subcommand [<expected>] from [<caretCmd>]' -TestCases ( |
| 142 | + # @{ caretCmd = 'vcpkg depend^'; expected = 'depend-info' }, |
| 143 | + # @{ caretCmd = 'vcpkg inst^'; expected = 'install' }, |
| 144 | + # @{ caretCmd = 'vcpkg int^'; expected = 'integrate' }, |
| 145 | + # @{ caretCmd = 'vcpkg rem^'; expected = 'remove' } |
| 146 | + # ) { |
| 147 | + # param($caretCmd, $expected) |
| 148 | + # @($caretCmd | Complete-InputCaret)[0] | Should -BeExactly $expected |
| 149 | + # } |
| 150 | + |
| 151 | + # It 'Should complete subcommand two-level [powershell] from [vcpkg integrate power^]' -Skip { |
| 152 | + # 'vcpkg integrate power^' | Complete-InputCaret | Should -Contain 'powershell' |
| 153 | + # } |
| 154 | + |
| 155 | + # } |
| 156 | + |
| 157 | + # Context -Skip 'Complete subcommand argument and options tests' { |
| 158 | + |
| 159 | + # It 'Should complete argument [<expected>] from [<caretCmd>]' -TestCases ( |
| 160 | + # @{ caretCmd = 'vcpkg install vcpkg-cmake^'; expectedContain = 'vcpkg-cmake-get-vars' }, |
| 161 | + # @{ caretCmd = 'vcpkg install vcpkg-cmake --^'; expectedContain = '--dry-run' } |
| 162 | + # ) { |
| 163 | + # param($caretCmd, $expected) |
| 164 | + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain |
| 165 | + # } |
| 166 | + |
| 167 | + # } |
| 168 | + |
| 169 | + # Context -Skip 'Complete complex tests' { |
| 170 | + |
| 171 | + # It 'Should complete complex line [<expected>] from [<caretCmd>]' -TestCases ( |
| 172 | + # @{ caretCmd = 'echo powershell | % { vcpkg ver^ $_ }; echo $?'; expectedContain = 'version' } |
| 173 | + # ) { |
| 174 | + # param($caretCmd, $expected) |
| 175 | + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain |
| 176 | + # } |
| 177 | + |
| 178 | + # } |
| 179 | + |
| 180 | +} |
0 commit comments