mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Add Format-Custom Tree object Pester Test
This commit is contained in:
1 parent
dd3ee79c89
commit
1504f9b64f
1 file changed
+256
@@ -26,6 +26,38 @@ Describe "Format-Custom" {
|
||||
|
||||
|
||||
Describe "Format-Custom DRT basic functionality" -Tags DRT{
|
||||
Add-Type -TypeDefinition @"
|
||||
public abstract class NamedItem
|
||||
{
|
||||
public string name;
|
||||
}
|
||||
|
||||
public abstract class MyContainerBase : NamedItem
|
||||
{
|
||||
public System.Collections.Generic.List<NamedItem> children = new System.Collections.Generic.List<NamedItem> ();
|
||||
}
|
||||
|
||||
public sealed class MyLeaf1 : NamedItem
|
||||
{
|
||||
public int val1 = 0;
|
||||
}
|
||||
|
||||
public sealed class MyLeaf2 : NamedItem
|
||||
{
|
||||
public int val2 = 0;
|
||||
}
|
||||
|
||||
public sealed class MyContainer1 : MyContainerBase
|
||||
{
|
||||
public string data1;
|
||||
}
|
||||
|
||||
public sealed class MyContainer2 : MyContainerBase
|
||||
{
|
||||
public string data2;
|
||||
}
|
||||
"@
|
||||
|
||||
It "Format-Custom with subobject should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
||||
$expectResult1 = "this is the name"
|
||||
$expectResult2 = "this is the name of the sub object"
|
||||
@@ -41,4 +73,228 @@ Describe "Format-Custom DRT basic functionality" -Tags DRT{
|
||||
$result | Should Match "one"
|
||||
$result | Should Match "two"
|
||||
}
|
||||
|
||||
It "Format-Custom with Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
||||
$expectedResult=@"
|
||||
class MyContainer1
|
||||
{
|
||||
data1 = data 1
|
||||
children =
|
||||
[
|
||||
class MyLeaf1
|
||||
{
|
||||
val1 = 10
|
||||
name = leaf 1
|
||||
}
|
||||
class MyLeaf2
|
||||
{
|
||||
val2 = 20
|
||||
name = leaf 2
|
||||
}
|
||||
]
|
||||
|
||||
name = container 1
|
||||
}
|
||||
|
||||
class MyContainer2
|
||||
{
|
||||
data2 = data 2
|
||||
children =
|
||||
[
|
||||
class MyLeaf1
|
||||
{
|
||||
val1 = 10
|
||||
name = leaf 1
|
||||
}
|
||||
class MyLeaf2
|
||||
{
|
||||
val2 = 20
|
||||
name = leaf 2
|
||||
}
|
||||
]
|
||||
|
||||
name = container 2
|
||||
}
|
||||
|
||||
class MyContainer2
|
||||
{
|
||||
data2 = data 2 deep
|
||||
children =
|
||||
[
|
||||
class MyContainer1
|
||||
{
|
||||
data1 = cx data
|
||||
children =
|
||||
[
|
||||
class MyLeaf1
|
||||
{
|
||||
val1 = 10
|
||||
name = leaf 1
|
||||
}
|
||||
class MyLeaf2
|
||||
{
|
||||
val2 = 20
|
||||
name = leaf 2
|
||||
}
|
||||
]
|
||||
|
||||
name = cx
|
||||
}
|
||||
]
|
||||
|
||||
name = container 2 deep
|
||||
}
|
||||
|
||||
class MyContainer1
|
||||
{
|
||||
data1 = cx data
|
||||
children =
|
||||
[
|
||||
class MyLeaf1
|
||||
{
|
||||
val1 = 10
|
||||
name = leaf 1
|
||||
}
|
||||
class MyLeaf2
|
||||
{
|
||||
val2 = 20
|
||||
name = leaf 2
|
||||
}
|
||||
]
|
||||
|
||||
name = cx
|
||||
}
|
||||
"@
|
||||
$leaf1 = New-Object MyLeaf1
|
||||
$leaf1.name = "leaf 1"
|
||||
$leaf1.val1 = 10
|
||||
|
||||
$leaf2 = New-Object MyLeaf2
|
||||
$leaf2.name = "leaf 2"
|
||||
$leaf2.val2 = 20
|
||||
|
||||
$c1 = New-Object MyContainer1
|
||||
$c1.name = "container 1"
|
||||
$c1.data1 = "data 1"
|
||||
$c1.children.Add($leaf1)
|
||||
$c1.children.Add($leaf2)
|
||||
|
||||
$c2 = New-Object MyContainer2
|
||||
$c2.name = "container 2"
|
||||
$c2.data2 = "data 2"
|
||||
$c2.children.Add($leaf1)
|
||||
$c2.children.Add($leaf2)
|
||||
|
||||
$cDeep = New-Object MyContainer2
|
||||
$cDeep.name = "container 2 deep"
|
||||
$cDeep.data2 = "data 2 deep"
|
||||
|
||||
$cx= New-Object MyContainer1
|
||||
$cx.name = "cx"
|
||||
$cx.data1 = "cx data"
|
||||
$cx.children.Add($leaf1)
|
||||
$cx.children.Add($leaf2)
|
||||
$cDeep.children.Add($cx)
|
||||
|
||||
$objectList = @($c1,$c2,$cDeep,$cx)
|
||||
$result = $objectList | Format-Custom | Out-String
|
||||
$result = $result -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$expectedResult = $expectedResult -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$result | Should Be $expectedResult
|
||||
}
|
||||
|
||||
It "Format-Custom with Empty Data Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
||||
$expectedResult=@"
|
||||
class MyContainer1
|
||||
{
|
||||
data1 =
|
||||
children =
|
||||
name =
|
||||
}
|
||||
"@
|
||||
|
||||
$c= New-Object MyContainer1
|
||||
$c.name = $null
|
||||
$c.data1 = $null
|
||||
$c.children = $null
|
||||
$objectList = @($c)
|
||||
|
||||
$result = $objectList | Format-Custom | Out-String
|
||||
$result = $result -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$expectedResult = $expectedResult -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$result | Should Be $expectedResult
|
||||
}
|
||||
|
||||
It "Format-Custom with Back Pointers Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
||||
$expectedResult=@"
|
||||
class MyContainer1
|
||||
{
|
||||
data1 =
|
||||
children =
|
||||
[
|
||||
class MyContainer1
|
||||
{
|
||||
data1 =
|
||||
children =
|
||||
[
|
||||
class MyContainer1
|
||||
{
|
||||
data1 =
|
||||
children =
|
||||
[
|
||||
MyContainer1
|
||||
]
|
||||
|
||||
name = ROOT
|
||||
}
|
||||
]
|
||||
|
||||
name = ROOT
|
||||
}
|
||||
]
|
||||
|
||||
name = ROOT
|
||||
}
|
||||
"@
|
||||
|
||||
$root= New-Object MyContainer1
|
||||
$root.name = "ROOT"
|
||||
$root.children.Add($root)
|
||||
$objectList = @($root)
|
||||
|
||||
$result = $objectList | Format-Custom | Out-String
|
||||
$result = $result -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$expectedResult = $expectedResult -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$result | Should Be $expectedResult
|
||||
}
|
||||
|
||||
It "Format-Custom with Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
||||
$expectedResult=@"
|
||||
class MyLeaf1
|
||||
{
|
||||
val1 = 10
|
||||
name = leaf 1
|
||||
}
|
||||
|
||||
class MyLeaf2
|
||||
{
|
||||
val2 = 20
|
||||
name = leaf 2
|
||||
}
|
||||
"@
|
||||
|
||||
$leaf1 = New-Object MyLeaf1
|
||||
$leaf1.name = "leaf 1"
|
||||
$leaf1.val1 = 10
|
||||
|
||||
$leaf2 = New-Object MyLeaf2
|
||||
$leaf2.name = "leaf 2"
|
||||
$leaf2.val2 = 20
|
||||
|
||||
$objectList = @($leaf1,$leaf2)
|
||||
$result = $objectList | Format-Custom | Out-String
|
||||
$result = $result -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$expectedResult = $expectedResult -replace "{","" -replace "}","" -replace " ","" -replace "`n",""
|
||||
$result | Should Be $expectedResult
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user