Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more object path tests #1122

Merged
merged 3 commits into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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