Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Shallow vs deep inclusive compare #26

Open

Description

@jyn514

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?

Activity

  1. davidpdrsn commented on Mar 1, 2022

    @davidpdrsn
    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?

  2. jyn514 commented on Mar 1, 2022

    @jyn514
    ContributorAuthor

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions