@@ -72,4 +72,71 @@ Describe "ArrayExpression Tests" -Tags "CI" {
7272 $result.Length | Should Be 1
7373 $result [0 ] | Should Be $null
7474 }
75+
76+ It " @([void](New-Item)) should create file" {
77+ try {
78+ $testFile = Join-Path $TestDrive (New-Guid )
79+ $result = @ ([void ](New-Item $testFile - ItemType File))
80+ # # file should be created
81+ $testFile | Should Exist
82+ # # the array should be empty
83+ $result.Count | Should Be 0
84+ } finally {
85+ Remove-Item $testFile - Force - ErrorAction SilentlyContinue
86+ }
87+ }
88+ }
89+
90+ Describe " ArrayLiteral Tests" - Tags " CI" {
91+ It " '[void](New-Item),2,3' should return a 3-element array and first element is AutomationNull" {
92+ try {
93+ $testFile = Join-Path $TestDrive (New-Guid )
94+ $result = [void ](New-Item $testFile - ItemType File), 2 , 3
95+ # # file should be created
96+ $testFile | Should Exist
97+ # # the array should contain 3 items
98+ $result.Count | Should Be 3
99+
100+ # # the first item should be AutomationNull
101+ $result [0 ] | ForEach-Object { " YES" } | Should Be $null
102+ $result | Measure-Object | ForEach-Object - MemberName Count | Should Be 2
103+ } finally {
104+ Remove-Item $testFile - Force - ErrorAction SilentlyContinue
105+ }
106+ }
107+
108+ It " '[void]1, [void](New-Item), [void]2' should return a 3-AutomationNull-element array" {
109+ try {
110+ $testFile = Join-Path $TestDrive (New-Guid )
111+ $result = [void ]1 , [void ](New-Item $testFile - ItemType File), [void ]2
112+ # # file should be created
113+ $testFile | Should Exist
114+ # # the array should contain 3 items
115+ $result.Count | Should Be 3
116+
117+ # # all items should be AutomationNull
118+ $result | ForEach-Object { " YES" } | Should Be $null
119+ } finally {
120+ Remove-Item $testFile - Force - ErrorAction SilentlyContinue
121+ }
122+ }
123+
124+ It " '[void]`$ arraylist1.Add(1), `$ arraylist2.Clear()' should return a 2-AutomationNull-element array" {
125+ $arraylist1 = [System.Collections.ArrayList ]::new()
126+ $arraylist2 = [System.Collections.ArrayList ]::new()
127+
128+ $arraylist2.Add (2 ) > $null
129+ $arraylist2.Count | Should Be 1
130+
131+ # # first item is a non-void method call
132+ # # second item is a void method call
133+ $result = [void ]$arraylist1.Add (1 ), $arraylist2.Clear ()
134+ $result.Count | Should Be 2
135+ $result | ForEach-Object { " YES" } | Should Be $null
136+
137+ $arraylist1.Count | Should Be 1
138+ $arraylist1 [0 ] | Should Be 1
139+
140+ $arraylist2.Count | Should Be 0
141+ }
75142}
0 commit comments