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

Equality Operator Seems Broken #38

Open
luke-revenue opened this issue Feb 16, 2024 · 1 comment
Open

Equality Operator Seems Broken #38

luke-revenue opened this issue Feb 16, 2024 · 1 comment

Comments

@luke-revenue
Copy link

luke-revenue commented Feb 16, 2024

Here's a test from a test suite I'm working on at work:

    @Test
    public void testJsonLogic_doubleEquals_operator() throws JsonProcessingException, JsonLogicException {

        // With graph-shaped data

        var apples = """
                { "a": { "b": "apples" } }
                """;
        var oranges = """
                { "a": { "b": "oranges"} }
                """;

        var areApples = """
                { "==": [ { "var": "a.b" }, "apples" ] }
                """;
        assertThat(JSON_LOGIC.apply(areApples, apples)).isEqualTo(FALSE /* should be TRUE */);
        assertThat(JSON_LOGIC.apply(areApples, oranges)).isEqualTo(FALSE);

        var areOranges = """
                { "==": [ { "var": "a.b" }, "oranges" ] }
                """;
        assertThat(JSON_LOGIC.apply(areOranges, apples)).isEqualTo(FALSE);
        assertThat(JSON_LOGIC.apply(areOranges, oranges)).isEqualTo(FALSE /* should be TRUE */);

        var areTheseThingsThemselves = """
                { "==": [ { "var": "a.b" }, { "var": "a.b" } ] }
                """;
        assertThat(JSON_LOGIC.apply(areTheseThingsThemselves, apples)).isEqualTo(TRUE);
        assertThat(JSON_LOGIC.apply(areTheseThingsThemselves, oranges)).isEqualTo(TRUE);

        var areTheseThingsTheSame = """
                { "==": [ { "var": "a.b" }, { "var": "c.d" } ] }
                """;
        var twoThings = """
                {
                    "a": { "b": "apples" },
                    "c": { "d": "oranges" }
                }
                """;
        var oneThing = """
                {
                    "a": { "b": "apples" },
                    "c": { "d": "apples" }
                }
                """;
        assertThat(JSON_LOGIC.apply(areTheseThingsTheSame, twoThings)).isEqualTo(TRUE /* should be FALSE */);
        assertThat(JSON_LOGIC.apply(areTheseThingsTheSame, oneThing)).isEqualTo(TRUE);

        // With primitive data

        var simpleApples = """
                { "a": "apples" }
                """;
        var simpleOranges = """
                { "a": "oranges" }
                """;

        var areSimpleApples = """
                { "==": [ { "var": "a" }, "apples" ] }
                """;
        assertThat(JSON_LOGIC.apply(areSimpleApples, simpleApples)).isEqualTo(FALSE /* should be TRUE */);
        assertThat(JSON_LOGIC.apply(areSimpleApples, simpleOranges)).isEqualTo(FALSE);
    }

Note that the test case passes, but shouldn't. Also note that the type of value passed doesn't seem to matter, either: I can replace all the strings like "apples" and "oranges" with boolean values true and false with no change in test outcome. I didn't check quite as thoroughly, but the cases I did check also allow for single values like "foo" to be replaced by list-like values (viz. [ "foo" ]) and the test outcome still doesn't change.

Maybe I'm missing something? But, my hunch is that variable expressions like { "var": "foo" } are resolving to null.

@brusog
Copy link

brusog commented Jul 16, 2024

I am also stuck due to this issue. Is there a workaround?

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