forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat-Table.Tests.ps1
More file actions
213 lines (182 loc) · 6.93 KB
/
Copy pathFormat-Table.Tests.ps1
File metadata and controls
213 lines (182 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
Describe "Format-Table" -Tags "CI" {
It "Should call format table on piped input without error" {
{ Get-Date | Format-Table } | Should Not Throw
{ Get-Date | ft } | Should Not Throw
}
It "Should return a format object data type" {
$val = (Get-Date | Format-Table | gm )
$val2 = (Get-Date | Format-Table | gm )
$val.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format"
$val2.TypeName | Should Match "Microsoft.Powershell.Commands.Internal.Format"
}
It "Should be able to be called with optional parameters" {
$v1 = (Get-Date | Format-Table *)
$v2 = (Get-Date | Format-Table -Property Hour)
$v3 = (Get-Date | Format-Table -GroupBy Hour)
$v12 = (Get-Date | ft *)
$v22 = (Get-Date | ft -Property Hour)
$v32 = (Get-Date | ft -GroupBy Hour)
}
}
Describe "Format-Table DRT Unit Tests" -Tags "CI" {
It "Format-Table with not existing table with force should throw PipelineStoppedException"{
$obj = New-Object -typename PSObject
try
{
$obj | Format-Table -view bar -force -EA Stop
Throw "Execution OK"
}
catch
{
$_.CategoryInfo | Should Match "PipelineStoppedException"
$_.FullyQualifiedErrorId | Should be "FormatViewNotFound,Microsoft.PowerShell.Commands.FormatTableCommand"
}
}
It "Format-Table with array should work" {
$al = (0..255)
$info = @{}
$info.array = $al
$result = $info|Format-Table|Out-String
$result | Should Match "array\s+{0, 1, 2, 3...}"
}
It "Format-Table with Negative Count should work" {
$FormatEnumerationLimit = -1
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1, 2}"
}
# Pending on issue#888
It "Format-Table with Zero Count should work" -Pending {
$FormatEnumerationLimit = 0
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{...}"
}
It "Format-Table with Less Count should work" {
$FormatEnumerationLimit = 1
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1...}"
}
It "Format-Table with More Count should work" {
$FormatEnumerationLimit = 10
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1, 2}"
}
It "Format-Table with Equal Count should work" {
$FormatEnumerationLimit = 2
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1, 2}"
}
# Pending on issue#888
It "Format-Table with Bogus Count should throw Exception" -Pending {
$FormatEnumerationLimit = "abc"
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1, 2}"
}
# Pending on issue#888
It "Format-Table with Var Deleted should throw Exception" -Pending {
$FormatEnumerationLimit = 2
Remove-Variable FormatEnumerationLimit
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1, 2}"
}
It "Format-Table with new line should work" {
$info = @{}
$info.name = "1\n2"
$result = $info|Format-Table|Out-String
$result | Should Match "name\s+1.+2"
}
It "Format-Table with ExposeBug920454 should work" {
$IP1 = [System.Net.IPAddress]::Parse("1.1.1.1")
$IP2 = [System.Net.IPAddress]::Parse("4fde:0000:0000:0002:0022:f376:255.59.171.63")
$IPs = New-Object System.Collections.ArrayList
$IPs.Add($IP1)
$IPs.Add($IP2)
$info = @{}
$info.test = $IPs
$result = $info|Format-Table|Out-String
$result | Should Match "test\s+{1.1.1.1, 4fde::2:22:f376:ff3b:ab3f}"
}
It "Format-Table with Autosize should work" {
$IP1 = [PSCustomObject]@{'name'='Bob';'size'=1234;'booleanValue'=$true;}
$IP2 = [PSCustomObject]@{'name'='Jim';'size'=5678;'booleanValue'=$false;}
$IPs = New-Object System.Collections.ArrayList
$IPs.Add($IP1)
$IPs.Add($IP2)
$result = $IPs|Format-Table -Autosize|Out-String
$result | Should Match "name size booleanValue"
$result | Should Match "---- ---- ------------"
$result | Should Match "Bob\s+1234\s+True"
$result | Should Match "Jim\s+5678\s+False"
}
It "Format-Table with No Objects for End-To-End should work"{
$p = @{}
$result = $p|Format-Table -Property "foo","bar"|Out-String
$result | Should BeNullOrEmpty
}
It "Format-Table with Null Objects for End-To-End should work"{
$p = $null
$result = $p|Format-Table -Property "foo","bar"|Out-String
$result | Should BeNullOrEmpty
}
#pending on issue#900
It "Format-Table with single line string for End-To-End should work" -pending{
$p = "single line string"
$result = $p|Format-Table -Property "foo","bar"|Out-String
$result | Should BeNullOrEmpty
}
#pending on issue#900
It "Format-Table with multiple line string for End-To-End should work" -pending{
$p = "Line1\nLine2"
$result = $p|Format-Table -Property "foo","bar"|Out-String
$result | Should BeNullOrEmpty
}
#pending on issue#900
It "Format-Table with string sequence for End-To-End should work" -pending{
$p = "Line1","Line2"
$result = $p|Format-Table -Property "foo","bar"|Out-String
$result | Should BeNullOrEmpty
}
#pending on issue#900
It "Format-Table with string sequence for End-To-End should work" -pending{
$p = "Line1","Line2"
$result = $p|Format-Table -Property "foo","bar"|Out-String
$result | Should BeNullOrEmpty
}
It "Format-Table with complex object for End-To-End should work" {
Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thu,Fri,Sat}"
$eto = New-Object MyDayOfWeek
$info = @{}
$info.intArray = 1,2,3,4
$info.arrayList = "string1","string2"
$info.enumerable = [MyDayOfWeek]$eto
$info.enumerableTestObject = $eto
$result = $info|Format-Table|Out-String
$result | Should Match "intArray\s+{1, 2, 3, 4}"
$result | Should Match "arrayList\s+{string1, string2}"
$result | Should Match "enumerable\s+Sun"
$result | Should Match "enumerableTestObject\s+Sun"
}
It "Format-Table with Expand Enumerable should work" {
$obj1 = "x 0","y 0"
$obj2 = "x 1","y 1"
$objs = New-Object System.Collections.ArrayList
$objs.Add($obj1)
$objs.Add($obj2)
$mo = [PSCustomObject]@{name = "this is name";sub = $objs}
$result1 = $mo|Format-Table -Expand CoreOnly|Out-String
$result1 | Should Match "name\s+sub"
$result1 | Should Match "this is name"
$result2 = $mo|Format-Table -Expand EnumOnly|Out-String
$result2 | Should Match "name\s+sub"
$result2 | Should Match "this is name\s+{x 0 y 0, x 1 y 1}"
$result3 = $mo|Format-Table -Expand Both|Out-String
$result3 | Should Match "name\s+sub"
$result3 | Should Match "this is name\s+{x 0 y 0, x 1 y 1}"
}
}