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

Feature request: [contains only deep] #2093

Closed
ericdriggs opened this issue Aug 18, 2022 · 4 comments
Closed

Feature request: [contains only deep] #2093

ericdriggs opened this issue Aug 18, 2022 · 4 comments
Assignees

Comments

@ericdriggs
Copy link

ericdriggs commented Aug 18, 2022

Feature: match contains deep only

#Current matchers don't have a syntax for a 1 line order insensitive exact values match
#Single line, order insensitive matching is actually they behavior I would prefer 99.99% of the time
#and it would be my vote to have this be the default behvaior of the == operator
#barring this, match deep only (or similar syntax) would address this use case

Background:
* def expected = { "a": [1, 2, 3, 4, 5] }
* def actualLarger = { "a": [1, 2, 3, 5, 4, 6] }
* def actualDifferentOrder = { "a": [1, 2, 3, 5, 4] }

#######

#fails per spec -- would love to see this pass by default as imo it's the least surprise behavior
Scenario: match equality per spec doesn't ignore order
* match expected == actualDifferentOrder

#######

#passes per spec -- this is the correct behavior
Scenario: by design 'match contains deep' ignores ordering but allows for extra entries

* match actualLarger contains deep expected

#######

#doesn't exist -- would solve this use case
#no preference on 'contains deep only' vs 'contains only deep'
Scenario: 'match contains deep only' would allow for order-insensitive exact value comparisons

* def expected = { "a": [1, 2, 3, 4, 5] }
* def actual = { "a": [1, 2, 3, 5, 4, 6] }
* match actualDifferentOrder contains deep only expected`
@ptrthomas
Copy link
Member

@ericdriggs okay, will consider for investigation. the assumption was the order of arrays ALWAYS matters, for example a list of "history" items, etc.

I do think a way to do an "exact but ignore array order" match is useful.

suggestions welcome for alternate syntax. contains only deep sounds good to me

@ericdriggs
Copy link
Author

After looking through JSON specs, I agree that by default json array ordering is important and should be strict.

@ptrthomas ptrthomas self-assigned this Oct 13, 2022
@ptrthomas ptrthomas added this to the 1.3.0 milestone Oct 13, 2022
ptrthomas added a commit that referenced this issue Nov 1, 2022
@ptrthomas ptrthomas added the fixed label Nov 1, 2022
@ptrthomas
Copy link
Member

@ericdriggs implemented. do try it out.

so this should work:

* def response = { foo: [ 'a', 'b' ] }
* match response contains only deep { foo: [ 'b', 'a' ] }

once you test a few cases, we can consider a short-cut for this, for example:

* match response ^= { foo: [ 'b', 'a' ] }

I would vote for this being the only short-cut we allow in the match syntax. we can also add it to the "inline" short-cuts here: https://github.com/karatelabs/karate#contains-short-cuts

@ptrthomas ptrthomas changed the title Feature request: contains deep only Feature request: contains only deep Nov 2, 2022
@ptrthomas ptrthomas changed the title Feature request: contains only deep Feature request: [contains only deep] Nov 2, 2022
@ptrthomas
Copy link
Member

1.3.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants