Add type inference for Select-Object command (#7171)

Add type inference for Select-Object command

Fixes #7170
This commit is contained in:
Staffan Gustafsson 2018-07-02 22:23:30 +02:00 committed by Travis Plunk
parent dbaa1add3a
commit 3c079b9d42
3 changed files with 506 additions and 291 deletions

1
.gitignore vendored
View file

@ -64,3 +64,4 @@ TestsResults*.xml
# Resharper settings
PowerShell.sln.DotSettings.user
*.msp
StyleCop.Cache

View file

@ -352,6 +352,24 @@ Describe "Type inference Tests" -tags "CI" {
}
}
It "Infers typeof Select-Object when Member is ExpandProperty" {
$res = [AstTypeInference]::InferTypeOf( { Get-ChildItem | Select-Object -ExpandProperty Directory }.Ast)
$res.Count | Should -Be 1
$res.Name | Should -Be "System.IO.DirectoryInfo"
}
It "Infers typeof Select-Object when No projection is done" {
$res = [AstTypeInference]::InferTypeOf( { "Hello" | Select-Object -First 1}.Ast)
$res.Count | Should -Be 1
$res.Name | Should -Be "System.String"
}
It "Don't Infer typeof Select-Object when projection is done" {
$res = [AstTypeInference]::InferTypeOf( { Get-ChildItem | Select-Object -Property Name}.Ast)
$res.Count | Should -Be 0
}
It "Infers type from OutputTypeAttribute" {
$res = [AstTypeInference]::InferTypeOf( { Get-Process -Id 2345 }.Ast)
$gpsOutput = [Microsoft.PowerShell.Commands.GetProcessCommand].GetCustomAttributes([System.Management.Automation.OutputTypeAttribute], $false).Type