Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
PSReadLine.Tests.ps169 linesDownload Raw Back to PSReadLine
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "PSReadLine" -tags "CI" {4    BeforeAll {5        if (Get-Module PSReadLine) {6            $originalEditMode = (Get-PSReadLineOption).EditMode7            Remove-Module PSReadLine8        }9    }10 11    It "Should import the module correctly" {12        Import-Module PSReadLine13        $module = Get-Module PSReadLine14        $module.Name | Should -BeExactly 'PSReadLine'15        $module.Version | Should -Match '^2.4.\d$'16    }17 18    It "Should be installed to `$PSHOME" {19        $module = Get-Module (Join-Path -Path $PSHOME -ChildPath "Modules" -AdditionalChildPath "PSReadLine") -ListAvailable20        $module.Name | Should -BeExactly 'PSReadLine'21        $module.Version | Should -Match '^2.4.\d$'22        $module.Path | Should -Be (Join-Path -Path $PSHOME -ChildPath "Modules/PSReadLine/PSReadLine.psd1")23    }24 25    It "Should use Emacs Bindings on Linux and macOS" -Skip:$IsWindows {26        (Get-PSReadLineOption).EditMode | Should -BeExactly 'Emacs'27        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+A" }).Function | Should -BeExactly 'BeginningOfLine'28    }29 30    It "Should use Windows Bindings on Windows" -Skip:(-not $IsWindows) {31        (Get-PSReadLineOption).EditMode | Should -BeExactly 'Windows'32        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+a" }).Function | Should -BeExactly 'SelectAll'33    }34 35    It "Should set the edit mode" {36        Set-PSReadLineOption -EditMode Windows37        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+A" }).Function | Should -BeExactly 'SelectAll'38 39        Set-PSReadLineOption -EditMode Emacs40        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+A" }).Function | Should -BeExactly 'BeginningOfLine'41    }42 43    It "Should allow custom bindings for plain keys" {44        Set-PSReadLineKeyHandler -Key '"' -Function SelfInsert45        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq '"' }).Function | Should -BeExactly 'SelfInsert'46    }47 48    It "Should report Capitalized bindings correctly" {49        Set-PSReadLineOption -EditMode Emacs50        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -ceq "Alt+b" }).Function | Should -BeExactly 'BackwardWord'51        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -ceq "Alt+B" }).Function | Should -BeExactly 'SelectBackwardWord'52    }53 54    It "Should ignore case when using Function binding" {55        $lowerCaseFunctionName = "yank"56        Set-PSReadLineKeyHandler "Ctrl+F24" -Function $lowerCaseFunctionName57        (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Ctrl+F24"}).Function | Should -BeExactly "Yank"58    }59 60    AfterAll {61        Remove-Module PSReadLine62 63        if ($originalEditMode) {64            Import-Module PSReadLine65            Set-PSReadLineOption -EditMode $originalEditMode66        }67    }68}69