packages feed

jsonlogic-hs-0.1.0.0: test/community/array/map.json

[
    "Basic Operations",
    {
        "description": "Map with identity function",
        "rule": {"map": [{"var": "integers"}, {"var": ""}]},
        "data": {"integers": [1, 2, 3]},
        "result": [1, 2, 3]
    },
    {
        "description": "Map with multiplication",
        "rule": {
            "map": [
                {"var": "integers"},
                {"*": [{"var": ""}, 2]}
            ]
        },
        "data": {"integers": [1, 2, 3]},
        "result": [2, 4, 6]
    },
    "Object Operations",
    {
        "description": "Map extracting single field from objects",
        "rule": {
            "map": [{"var": "desserts"}, {"var": "qty"}]
        },
        "data": {
            "desserts": [
                {"name": "apple", "qty": 1},
                {"name": "brownie", "qty": 2},
                {"name": "cupcake", "qty": 3}
            ]
        },
        "result": [1, 2, 3]
    },
    {
        "description": "Map with complex object transformation",
        "rule": {
            "map": [
                {"var": "items"},
                {"+": [{"var": "price"}, {"var": "tax"}]}
            ]
        },
        "data": {
            "items": [
                {"price": 100, "tax": 10},
                {"price": 200, "tax": 20}
            ]
        },
        "result": [110, 220]
    },
    "Edge Cases",
    {
        "description": "Map on null array returns empty array",
        "rule": {
            "map": [
                {"var": "missing"},
                {"*": [{"var": ""}, 2]}
            ]
        },
        "data": null,
        "result": []
    },
    {
        "description": "Map on empty array returns empty array",
        "rule": {
            "map": [
                {"var": "empty"},
                {"*": [{"var": ""}, 2]}
            ]
        },
        "data": {"empty": []},
        "result": []
    },
    {
        "description": "Map with null mapper should throw",
        "rule": {"map": [{"var": "integers"}, null]},
        "data": {"integers": [1, 2, 3]},
        "error": {"type": "Invalid Arguments"}
    },
    {
        "description": "Map with null array should throw",
        "rule": {"map": [null, {"var": ""}]},
        "data": null,
        "error": {"type": "Invalid Arguments"}
    },
    "Complex Transformations",
    {
        "description": "Map with nested logic operations",
        "rule": {
            "map": [
                {"var": "values"},
                {"if": [
                    {">": [{"var": ""}, 0]},
                    "positive",
                    "negative"
                ]}
            ]
        },
        "data": {"values": [-1, 0, 1]},
        "result": ["negative", "negative", "positive"]
    },
    {
        "description": "Map with string operations",
        "rule": {
            "map": [
                {"var": "names"},
                {"cat": [{"var": ""}, "!!"]}
            ]
        },
        "data": {"names": ["hello", "world"]},
        "result": ["hello!!", "world!!"]
    },
    "Path Resolution",
    {
        "description": "Map with nested path access",
        "rule": {
            "map": [
                {"var": "users"},
                {"var": "profile.name"}
            ]
        },
        "data": {
            "users": [
                {"profile": {"name": "John"}},
                {"profile": {"name": "Jane"}}
            ]
        },
        "result": ["John", "Jane"]
    },
    {
        "description": "Map with missing nested paths",
        "rule": {
            "map": [
                {"var": "users"},
                {"var": "profile.age"}
            ]
        },
        "data": {
            "users": [
                {"profile": {"name": "John"}},
                {"profile": {"name": "Jane"}}
            ]
        },
        "result": [null, null]
    },
    "Type Coercion",
    {
        "description": "Map with numeric coercion",
        "rule": {
            "map": [
                {"var": "mixed"},
                {"+": [{"var": ""}, 1]}
            ]
        },
        "data": {"mixed": ["1", 2, "3"]},
        "result": [2, 3, 4]
    },
    {
        "description": "Map with boolean coercion",
        "rule": {
            "map": [
                {"var": "values"},
                {"!!": [{"var": ""}]}
            ]
        },
        "data": {"values": [0, 1, "", "hello", [], [1]]},
        "result": [false, true, false, true, false, true]
    }
]