Skip to content

Commit 2caf08e

Browse files
committed
Resolve remarks
1 parent d5c3f86 commit 2caf08e

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

dsc/tests/dsc_functions.tests.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ Describe 'tests for function expressions' {
118118
@{ expression = "[intersection(parameters('thirdObject'), parameters('fourthObject'))]"; expected = [pscustomobject]@{ three = 'd' } }
119119
@{ expression = "[intersection(parameters('firstArray'), parameters('thirdArray'))]"; expected = @() }
120120
@{ expression = "[intersection(parameters('firstObject'), parameters('firstArray'))]"; isError = $true }
121+
# Test with 3 arrays - should find common elements across all three
122+
@{ expression = "[intersection(parameters('firstArray'), parameters('secondArray'), parameters('fifthArray'))]"; expected = @('cd') }
123+
# Test with 3 objects - should find properties with matching key-value pairs across all three
124+
@{ expression = "[intersection(parameters('firstObject'), parameters('secondObject'), parameters('sixthObject'))]"; expected = [pscustomobject]@{ two = 'b' } }
125+
# Test with nested objects - should match deep equality
126+
@{ expression = "[intersection(parameters('nestedObject1'), parameters('nestedObject2'))]"; expected = [pscustomobject]@{
127+
shared = [pscustomobject]@{ value = 42; flag = $true }
128+
level = 1
129+
} }
130+
# Test with nested objects - no common nested properties
131+
@{ expression = "[intersection(parameters('nestedObject1'), parameters('nestedObject3'))]"; expected = [pscustomobject]@{ level = 1 } }
132+
# Test with 3 nested objects
133+
@{ expression = "[intersection(parameters('nestedObject1'), parameters('nestedObject2'), parameters('nestedObject4'))]"; expected = [pscustomobject]@{ level = 1 } }
121134
) {
122135
param($expression, $expected, $isError)
123136

@@ -144,6 +157,42 @@ Describe 'tests for function expressions' {
144157
defaultValue:
145158
three: d
146159
four: e
160+
sixthObject:
161+
type: object
162+
defaultValue:
163+
two: b
164+
five: f
165+
nestedObject1:
166+
type: object
167+
defaultValue:
168+
shared:
169+
value: 42
170+
flag: true
171+
level: 1
172+
unique1: test
173+
nestedObject2:
174+
type: object
175+
defaultValue:
176+
shared:
177+
value: 42
178+
flag: true
179+
level: 1
180+
unique2: test
181+
nestedObject3:
182+
type: object
183+
defaultValue:
184+
shared:
185+
value: 24
186+
flag: true
187+
level: 1
188+
unique3: test
189+
nestedObject4:
190+
type: object
191+
defaultValue:
192+
level: 1
193+
different:
194+
value: 100
195+
flag: false
147196
firstArray:
148197
type: array
149198
defaultValue:
@@ -165,6 +214,11 @@ Describe 'tests for function expressions' {
165214
- gh
166215
- ef
167216
- ij
217+
fifthArray:
218+
type: array
219+
defaultValue:
220+
- cd
221+
- kl
168222
resources:
169223
- name: Echo
170224
type: Microsoft.DSC.Debug/Echo

dsc_lib/src/functions/intersection.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ impl Function for Intersection {
3131
fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
3232
debug!("{}", t!("functions.intersection.invoked"));
3333

34-
if args[0].is_array() {
35-
let first_array = args[0].as_array().unwrap();
34+
if let Some(first_array) = args[0].as_array() {
3635
let mut result = Vec::new();
3736

3837
for item in first_array {
@@ -57,8 +56,7 @@ impl Function for Intersection {
5756
return Ok(Value::Array(result));
5857
}
5958

60-
if args[0].is_object() {
61-
let first_object = args[0].as_object().unwrap();
59+
if let Some(first_object) = args[0].as_object() {
6260
let mut result = Map::new();
6361

6462
for (key, value) in first_object {

0 commit comments

Comments
 (0)