Allow combining of -Skip and -SkipLast parameters in Select-Object cmdlet. (#18849)

* Added SkipLast parameter set to Skip parameter and updated tests

* Using Should -BeExactly with string

* Update test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1

---------

Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
Co-authored-by: Travis Plunk <github@ez13.net>
This commit is contained in:
Armaan Mcleod
2023-05-02 13:07:32 -07:00
committed by GitHub
co-authored by Travis Plunk Travis Plunk
parent 8135167827
commit 07e041fe10
2 changed files with 25 additions and 1 deletions
@@ -231,6 +231,29 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" {
$results[1] | Should -Be 3
}
It "Select-Object with SkipLast should work" {
$results = "1", "2", "3" | Select-Object -SkipLast 1
$results.Count | Should -Be 2
$results[0] | Should -BeExactly "1"
$results[1] | Should -BeExactly "2"
}
It "Select-Object with Skip and SkipLast should work" {
$results = "1", "2", "3" | Select-Object -Skip 1 -SkipLast 1
$results.Count | Should -Be 1
$results[0] | Should -BeExactly "2"
}
It "Select-Object with Skip and SkipLast should work with Skip overlapping SkipLast" {
$results = "1", "2" | Select-Object -Skip 2 -SkipLast 1
$results. Count | Should -Be 0
}
It "Select-Object with Skip and SkipLast should work with skiplast overlapping skip" {
$results = "1", "2" | Select-Object -Skip 1 -SkipLast 2
$results. Count | Should -Be 0
}
It "Select-Object with Index should work" {
$results = "1", "2", "3" | Select-Object -Index 2
$results.Count | Should -Be 1