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

Shallow vs deep inclusive compare #26

Open
jyn514 opened this issue Mar 1, 2022 · 2 comments
Open

Shallow vs deep inclusive compare #26

jyn514 opened this issue Mar 1, 2022 · 2 comments

Comments

@jyn514
Copy link
Contributor

jyn514 commented Mar 1, 2022

I ran the following test just now, which passed:

        assert_json_include!(actual: &serialized, expected: serde_json::json!({
            "x": [0],
            "y": [1, 3],
        }))

Then I changed it to

        assert_json_include!(actual: &serialized, expected: serde_json::json!({
            "x": [0, 2],
            "y": [1, 3],
        }))

which also passed.

I think what's going on is that the Inclusive compare mode is being passed recursively, instead of only for the outer object. That's very non-intuitive for me, I'd expect it to only be for the keys and not the inner values. Would it be possible to add a new mode that does a shallow inclusive compare instead of a deep inclusive compare?

@davidpdrsn
Copy link
Owner

I think the current setup works well for deeply nested objects where you only care parts of it changing. But you're right, for arrays that might be a little confusing. Though I would argue things work as intended based on what you posted. The first one is a subset of the second, so seems ok to me.

Can you give some more examples of how such a swallow mode would work?

@jyn514
Copy link
Contributor Author

jyn514 commented Mar 1, 2022

@davidpdrsn I'd expect to be inclusive for the outer object but exact for everything else. For example, these would all pass:

assert_json_include_shallow!(actual: json!([1, 2, 3]), expected: json!([1, 2]));
assert_json_include_shallow!(actual: json!({"x": [1, 2, 3]}, "y": 0), expected: json!({"x": [1, 2, 3]}));

but these would all fail:

assert_json_include_shallow!(actual: json!({"x": [1, 2, 3]}), expected: json!({"x": [1, 2]}));
assert_json_include_shallow!(actual: json!({"x": {"y": 0, "z": 1}}), expected: json!({"x": {"y": 0}}));

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

No branches or pull requests

2 participants