diff --git a/test/Find-Member.Tests.ps1 b/test/Find-Member.Tests.ps1 index 82f5f99..0cd2f45 100644 --- a/test/Find-Member.Tests.ps1 +++ b/test/Find-Member.Tests.ps1 @@ -18,7 +18,7 @@ Describe 'Find-Member cmdlet tests' { } It 'filters passed members' { - $source = [type] | Find-Member + $source = [powershell] | Find-Member -Force $results = $source | Find-Member -Static $results | ShouldAll { $_ -in $source } @@ -26,6 +26,21 @@ Describe 'Find-Member cmdlet tests' { } } + It 'gets all members with no input' { + $results = Find-Member + $results.Count | Should -BeGreaterThan 10000 + } + + It 'matches nonpublic members with Force' { + $result = $ExecutionContext.SessionState | Find-Member -Force + + # A nonpublic member is present + $result | ShouldAny { $_.Name -eq 'Internal' -and 'Property' -eq $_.MemberType } + + # A public member is still present + $result | ShouldAny { $_.Name -eq 'Module' -and 'Property' -eq $_.MemberType } + } + It 'matches with FilterScript' { $result = [powershell] | Find-Member -FilterScript { $_.Name -eq 'Create' -and $_.GetParameters().Count -eq 0 } @@ -58,6 +73,31 @@ Describe 'Find-Member cmdlet tests' { ShouldAny { $_.Name -eq 'Create' } } + It 'return type matches constructors' { + [System.Collections.Generic.List[string]] | + Find-Member -ReturnType System.Collections.Generic.List[string] | + ShouldAny { 'Constructor' -eq $_.MemberType } + } + + It 'unwraps target types with elements' { + $result = [System.Management.Automation.Language.Parser] | + Find-Member -ParameterType System.Management.Automation.Language.Token + + $result | ShouldAny { + ($parameters = $_.GetParameters()) -and + $parameters[1].ParameterType.IsByRef -and + $parameters[1].ParameterType.GetElementType().IsArray + } + } + + It 'return type matches fields' { + $contextType = Find-Type ExecutionContext -Namespace *Automation -Force + $result = $ExecutionContext | Find-Member -ReturnType $contextType -Force + + $result.MemberType | Should -Be Field + $result.FieldType | Should -Be $contextType + } + It 'filters to virtual members' { $results = [runspace] | Find-Member -Virtual @@ -89,4 +129,15 @@ Describe 'Find-Member cmdlet tests' { $results | ShouldAll { $_.Name -ne 'AddScript' } $results | ShouldAny { $_.Name -eq 'Create' } } + + It 'gets members for passed objects only once per type' { + $powershells = [powershell]::Create(), [powershell]::Create() + try { + $result = $powershells | Find-Member + } finally { + $powershells.ForEach('Dispose') + } + + $result.Where{ $_.Name -eq 'Create' }.Count | Should -Be 3 + } } diff --git a/test/Find-Type.Tests.ps1 b/test/Find-Type.Tests.ps1 index 2f776e5..0b8f65e 100644 --- a/test/Find-Type.Tests.ps1 +++ b/test/Find-Type.Tests.ps1 @@ -35,6 +35,22 @@ Describe 'Find-Type tests' { It 'matches by namespace' { Find-Type -Namespace System.Timers | ShouldAll { $_.Namespace -eq 'System.Timers' } } + It 'matches by full name' { + Find-Type -FullName System.Management.Automation.ProxyCommand | + Should -Be ([System.Management.Automation.ProxyCommand]) + } + It 'matches by name with regex' { + Find-Type "Runspace(Factory|ConnectionInfo)" -RegularExpression | + Should -Be ([runspacefactory], [System.Management.Automation.Runspaces.RunspaceConnectionInfo]) + } + It 'matches by namespace with regex' { + Find-Type MethodAttributes -Namespace 'System\.(?!Reflection).+' -RegularExpression | + Should -Be ([System.Management.Automation.Language.MethodAttributes]) + } + It 'matches by full name with regex' { + Find-Type -FullName 'System\.(?!Threading)\w+\.Timer$' -RegularExpression | + Should -Be ([System.Timers.Timer]) + } It 'matches by base class' { $results = Find-Type -InheritsType System.Management.Automation.Language.Ast diff --git a/test/Get-Parameter.Tests.ps1 b/test/Get-Parameter.Tests.ps1 index 36a602c..0cfe83c 100644 --- a/test/Get-Parameter.Tests.ps1 +++ b/test/Get-Parameter.Tests.ps1 @@ -10,4 +10,9 @@ Describe 'Get-Parameter tests' { $results | ShouldAny { $_.Name -eq 'asyncResult' } } + + It 'returns nothing without input' { + Get-Parameter | Should -BeNullOrEmpty + $null | Get-Parameter | Should -BeNullOrEmpty + } }