2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "PSReadLine" -tags "CI" {
|
2016-05-04 14:42:04 -07:00
|
|
|
BeforeAll {
|
|
|
|
|
if (Get-Module PSReadLine) {
|
|
|
|
|
$originalEditMode = (Get-PSReadLineOption).EditMode
|
|
|
|
|
Remove-Module PSReadLine
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should import the module correctly" {
|
|
|
|
|
Import-Module PSReadLine
|
|
|
|
|
$module = Get-Module PSReadLine
|
2018-03-29 22:22:26 -07:00
|
|
|
$module.Name | Should -BeExactly 'PSReadLine'
|
2025-09-30 12:32:43 -07:00
|
|
|
$module.Version | Should -Match '^2.4.\d$'
|
2019-04-04 23:01:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be installed to `$PSHOME" {
|
|
|
|
|
$module = Get-Module (Join-Path -Path $PSHOME -ChildPath "Modules" -AdditionalChildPath "PSReadLine") -ListAvailable
|
|
|
|
|
$module.Name | Should -BeExactly 'PSReadLine'
|
2025-09-30 12:32:43 -07:00
|
|
|
$module.Version | Should -Match '^2.4.\d$'
|
2019-04-04 23:01:01 -07:00
|
|
|
$module.Path | Should -Be (Join-Path -Path $PSHOME -ChildPath "Modules/PSReadLine/PSReadLine.psd1")
|
2016-05-04 14:42:04 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-07 13:00:30 +01:00
|
|
|
It "Should use Emacs Bindings on Linux and macOS" -Skip:$IsWindows {
|
2018-03-29 22:22:26 -07:00
|
|
|
(Get-PSReadLineOption).EditMode | Should -BeExactly 'Emacs'
|
2020-05-07 13:00:30 +01:00
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+A" }).Function | Should -BeExactly 'BeginningOfLine'
|
2016-07-15 13:43:29 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-07 13:00:30 +01:00
|
|
|
It "Should use Windows Bindings on Windows" -Skip:(-not $IsWindows) {
|
2018-03-29 22:22:26 -07:00
|
|
|
(Get-PSReadLineOption).EditMode | Should -BeExactly 'Windows'
|
2020-05-07 13:00:30 +01:00
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+a" }).Function | Should -BeExactly 'SelectAll'
|
2016-07-15 13:43:29 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-04 14:42:04 -07:00
|
|
|
It "Should set the edit mode" {
|
2020-05-07 13:00:30 +01:00
|
|
|
Set-PSReadLineOption -EditMode Windows
|
|
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+A" }).Function | Should -BeExactly 'SelectAll'
|
2016-05-04 14:42:04 -07:00
|
|
|
|
2020-05-07 13:00:30 +01:00
|
|
|
Set-PSReadLineOption -EditMode Emacs
|
|
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+A" }).Function | Should -BeExactly 'BeginningOfLine'
|
2016-05-04 14:42:04 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 21:57:10 -07:00
|
|
|
It "Should allow custom bindings for plain keys" {
|
2020-05-07 13:00:30 +01:00
|
|
|
Set-PSReadLineKeyHandler -Key '"' -Function SelfInsert
|
2018-03-29 22:22:26 -07:00
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq '"' }).Function | Should -BeExactly 'SelfInsert'
|
2016-07-28 21:57:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should report Capitalized bindings correctly" {
|
2020-05-07 13:00:30 +01:00
|
|
|
Set-PSReadLineOption -EditMode Emacs
|
2018-03-29 22:22:26 -07:00
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -ceq "Alt+b" }).Function | Should -BeExactly 'BackwardWord'
|
|
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -ceq "Alt+B" }).Function | Should -BeExactly 'SelectBackwardWord'
|
2016-07-28 21:57:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-07 17:24:35 -04:00
|
|
|
It "Should ignore case when using Function binding" {
|
|
|
|
|
$lowerCaseFunctionName = "yank"
|
2020-05-07 13:00:30 +01:00
|
|
|
Set-PSReadLineKeyHandler "Ctrl+F24" -Function $lowerCaseFunctionName
|
|
|
|
|
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+F24"}).Function | Should -BeExactly "Yank"
|
2017-08-07 17:24:35 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-04 14:42:04 -07:00
|
|
|
AfterAll {
|
|
|
|
|
Remove-Module PSReadLine
|
|
|
|
|
|
|
|
|
|
if ($originalEditMode) {
|
|
|
|
|
Import-Module PSReadLine
|
2020-05-07 13:00:30 +01:00
|
|
|
Set-PSReadLineOption -EditMode $originalEditMode
|
2016-05-04 14:42:04 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|