From 1f83da30c5714fbced07ae68aaa33180440f3b0a Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 26 Dec 2022 23:13:55 +1100 Subject: [PATCH 1/3] Added SkipLast parameter set to Skip parameter and updated tests --- .../commands/utility/Select-Object.cs | 3 ++- .../Select-Object.Tests.ps1 | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs index d7ce5310c98..4eceea33301 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs @@ -144,10 +144,11 @@ public int First private bool _firstOrLastSpecified; /// - /// Skips the specified number of items from top when used with First, from end when used with Last. + /// Skips the specified number of items from top when used with First, from end when used with Last or SkipLast. /// /// [Parameter(ParameterSetName = "DefaultParameter")] + [Parameter(ParameterSetName = "SkipLastParameter")] [ValidateRange(0, int.MaxValue)] public int Skip { get; set; } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index 05885698392..f48497d8520 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -231,6 +231,19 @@ 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 -Be 1 + $results[1] | Should -Be 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 -Be 2 + } + It "Select-Object with Index should work" { $results = "1", "2", "3" | Select-Object -Index 2 $results.Count | Should -Be 1 From 0266e78eddb9e0e5c54f750ac9b5626e9d01b796 Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 26 Dec 2022 23:20:52 +1100 Subject: [PATCH 2/3] Using Should -BeExactly with string --- .../Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index f48497d8520..a59f9f5a6ec 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -234,14 +234,14 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { It "Select-Object with SkipLast should work" { $results = "1", "2", "3" | Select-Object -SkipLast 1 $results.Count | Should -Be 2 - $results[0] | Should -Be 1 - $results[1] | 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 -Be 2 + $results[0] | Should -BeExactly "2" } It "Select-Object with Index should work" { From 8dada6d831fc7b622a2984a4577d6f3435d093d0 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 1 May 2023 14:58:36 -0700 Subject: [PATCH 3/3] Update test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 --- .../Select-Object.Tests.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index a59f9f5a6ec..04284453435 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -243,6 +243,16 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { $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