Skip to content

Commit

Permalink
Added more object path tests (#1122)
Browse files Browse the repository at this point in the history
* Add tests for current ref comparisons with no dot selector

* Updated changelog
  • Loading branch information
ArmaanMcleod authored Jun 19, 2022
1 parent d58ba71 commit b2b6ffb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ What's changed since pre-release v2.2.0-B0021:
[#1117](https://github.com/microsoft/PSRule/issues/1117)
- Fixed piped input does not respect excluded paths by @BernieWhite.
[#1114](https://github.com/microsoft/PSRule/issues/1114)
- Engineering:
- Added more object path tests by @ArmaanMcleod.
[#1110](https://github.com/microsoft/PSRule/issues/1110)

## v2.2.0-B0021 (pre-release)

Expand Down
24 changes: 24 additions & 0 deletions tests/PSRule.Tests/PathExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ public void WithOrFilter()
Assert.Equal("2", actual[1]);
Assert.Equal("1", actual[2]);
Assert.Equal("2", actual[3]);

expression = PathExpression.Create("$[*].Spec.Properties.array2[?(@ == '1' || @ == '2' || @ == '3')]");
Assert.True(expression.IsArray);
Assert.True(expression.TryGet(testObject, false, out actual));
Assert.NotNull(actual);
Assert.Equal(6, actual.Length);
Assert.Equal("1", actual[0]);
Assert.Equal("2", actual[1]);
Assert.Equal("3", actual[2]);
Assert.Equal("1", actual[3]);
Assert.Equal("2", actual[4]);
Assert.Equal("3", actual[5]);
}

[Fact]
Expand All @@ -136,6 +148,18 @@ public void WithAndFilter()
Assert.Equal(2, actual.Length);
Assert.Equal("1", actual[0]);
Assert.Equal("1", actual[1]);

expression = PathExpression.Create("$[*].Spec.Properties.array2[?(@ == '1' && @ == '2')]");
Assert.False(expression.TryGet(testObject, false, out actual));
Assert.Null(actual);

expression = PathExpression.Create("$[*].Spec.Properties.array2[?(@ == '1' && @ == '1')]");
Assert.True(expression.IsArray);
Assert.True(expression.TryGet(testObject, false, out actual));
Assert.NotNull(actual);
Assert.Equal(2, actual.Length);
Assert.Equal("1", actual[0]);
Assert.Equal("1", actual[1]);
}

[Fact]
Expand Down

0 comments on commit b2b6ffb

Please sign in to comment.