From baecea66bd6f79bdfe9d20fcf59fb5b6ed262ecc Mon Sep 17 00:00:00 2001 From: iSazonov Date: Tue, 28 Mar 2017 14:19:03 +0300 Subject: [PATCH 1/2] Add tab completion for Select-Object -ExcludeProperty -ExpandProperty --- .../CommandCompletion/CompletionCompleters.cs | 11 ++++++++++- .../powershell/Host/TabCompletion/BugFix.Tests.ps1 | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index a9f6b9edc1a..f7eb2ea69f5 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -2249,7 +2249,6 @@ private static void NativeCommandArgumentCompletion( } case "Group-Object": case "Measure-Object": - case "Select-Object": case "Sort-Object": case "Where-Object": case "Format-Custom": @@ -2263,6 +2262,16 @@ private static void NativeCommandArgumentCompletion( } break; } + case "Select-Object": + { + if (parameterName.Equals("Property", StringComparison.OrdinalIgnoreCase) + || parameterName.Equals("ExcludeProperty", StringComparison.OrdinalIgnoreCase) + || parameterName.Equals("ExpandProperty", StringComparison.OrdinalIgnoreCase)) + { + NativeCompletionMemberName(context.WordToComplete, result, commandAst, context); + } + break; + } case "New-Object": { diff --git a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 index 38feaceb4b8..a0915ba46ae 100644 --- a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 @@ -35,4 +35,18 @@ Describe "Tab completion bug fix" -Tags "CI" { $result.CompletionMatches[1].CompletionText | Should Be "-NoClobber" $result.CompletionMatches[2].CompletionText | Should Be "-NoOverwrite" } + It "Issue#3416 - 'Select-Object -ExcludeProperty ' should work" { + $cmd = "Get-Date | Select-Object -ExcludeProperty " + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be 15 + $result.CompletionMatches[0].CompletionText | Should Be "Date" + $result.CompletionMatches[1].CompletionText | Should Be "DateTime" + } + It "Issue#3416 - 'Select-Object -ExpandProperty ' should work" { + $cmd = "Get-Date | Select-Object -ExpandProperty " + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be 15 + $result.CompletionMatches[0].CompletionText | Should Be "Date" + $result.CompletionMatches[1].CompletionText | Should Be "DateTime" + } } From 8cdc962a5bc0c534c743b9c00e6e1a184e7f39cd Mon Sep 17 00:00:00 2001 From: iSazonov Date: Wed, 29 Mar 2017 07:10:49 +0300 Subject: [PATCH 2/2] Make tests more reliable --- .../Host/TabCompletion/BugFix.Tests.ps1 | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 index a0915ba46ae..d97d4a36688 100644 --- a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 @@ -35,18 +35,23 @@ Describe "Tab completion bug fix" -Tags "CI" { $result.CompletionMatches[1].CompletionText | Should Be "-NoClobber" $result.CompletionMatches[2].CompletionText | Should Be "-NoOverwrite" } - It "Issue#3416 - 'Select-Object -ExcludeProperty ' should work" { - $cmd = "Get-Date | Select-Object -ExcludeProperty " - $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length - $result.CompletionMatches.Count | Should Be 15 - $result.CompletionMatches[0].CompletionText | Should Be "Date" - $result.CompletionMatches[1].CompletionText | Should Be "DateTime" - } - It "Issue#3416 - 'Select-Object -ExpandProperty ' should work" { - $cmd = "Get-Date | Select-Object -ExpandProperty " - $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length - $result.CompletionMatches.Count | Should Be 15 - $result.CompletionMatches[0].CompletionText | Should Be "Date" - $result.CompletionMatches[1].CompletionText | Should Be "DateTime" + Context "Issue#3416 - 'Select-Object'" { + BeforeAll { + $DatetimeProperties = @((Get-Date).psobject.baseobject.psobject.properties) | Sort-Object -Property Name + } + It "Issue#3416 - 'Select-Object -ExcludeProperty ' should work" { + $cmd = "Get-Date | Select-Object -ExcludeProperty " + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be $DatetimeProperties.Count + $result.CompletionMatches[0].CompletionText | Should Be $DatetimeProperties[0].Name # Date + $result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime + } + It "Issue#3416 - 'Select-Object -ExpandProperty ' should work" { + $cmd = "Get-Date | Select-Object -ExpandProperty " + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be $DatetimeProperties.Count + $result.CompletionMatches[0].CompletionText | Should Be $DatetimeProperties[0].Name # Date + $result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime + } } }