datalogic-rs 4.0.21

A fast, type-safe Rust implementation of JSONLogic for evaluating logical rules as JSON. Perfect for business rules engines and dynamic filtering in Rust applications.
Documentation
[
    "# Collection of Plus Operator Tests",
    {
        "description": "Addition",
        "rule": { "+": [1, 2] },
        "result": 3,
        "data": null
    },
    {
        "description": "Addition (2)",
        "rule": { "+": [5, 12] },
        "result": 17,
        "data": null
    },
    {
        "description": "Addition with Multiple Operands",
        "rule": { "+": [1, 2, 3, 4] },
        "result": 10,
        "data": null
    },
    {
        "description": "Addition with Negative Numbers",
        "rule": { "+": [-1, 0, 5] },
        "result": 4,
        "data": null
    },
    {
        "description": "Addition with Strings",
        "rule": { "+": ["1", "2", "3"] },
        "result": 6,
        "data": null
    },
    {
        "description": "Addition with Booleans",
        "rule": { "+": [true, false, true] },
        "result": 2,
        "data": null
    },
    {
        "description": "Addition with Multiple Value Types",
        "rule": { "+": [1, "2", 3, "4", "", true, false, null] },
        "result": 11,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand (Number)",
        "rule": { "+": [1] },
        "result": 1,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand (Negative Number)",
        "rule": { "+": [-1] },
        "result": -1,
        "data": null
    },
    {
        "description": "Plus Operator with zero operands is zero",
        "rule": { "+": [] },
        "result": 0,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (Number)",
        "rule": { "+": 1 },
        "result": 1,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (0)",
        "rule": { "+": 0 },
        "result": 0,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand (String)",
        "rule": { "+": ["1"] },
        "result": 1,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (Negative Number String)",
        "rule": { "+": "-1" },
        "result": -1,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (String Decimal)",
        "rule": { "+": "1.5" },
        "result": 1.5,
        "data": null,
        "decimal": true
    },
    {
        "description": "Plus Operator with Single Operand, Direct (String Negative Decimal)",
        "rule": { "+": "-1.5" },
        "result": -1.5,
        "data": null,
        "decimal": true
    },
    {
        "description": "Plus Operator with Single Operand, Direct (String 0.5)",
        "rule": { "+": "0.5" },
        "result": 0.5,
        "data": null,
        "decimal": true
    },
    {
        "description": "Plus Operator with Single Operand, Direct (String 1e2)",
        "rule": { "+": "1e2" },
        "result": 100,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (String 0)",
        "rule": { "+": "0" },
        "result": 0,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (true)",
        "rule": { "+": true },
        "result": 1,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (false)",
        "rule": { "+": false },
        "result": 0,
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct (Empty String)",
        "rule": { "+": "" },
        "result": 0,
        "data": null
    },
    {
        "description": "Plus Operator with a Single Operand, Direct (null)",
        "rule": { "+": null },
        "result": 0,
        "data": null
    },
    {
        "description": "Addition with val",
        "rule": { "+": [{ "val": "x" }, { "val": "y" }] },
        "result": 3,
        "data": { "x": 1, "y": 2 }
    },
    {
        "description": "Addition with string produces NaN",
        "rule": { "+": ["Hey", 1] },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Addition with Array produces NaN",
        "rule": { "+": [[1], 1] },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Addition with Array from context produces NaN",
        "rule": { "+": [{ "val": "x" }, 1] },
        "error": { "type": "NaN" },
        "data": { "x": [1] }
    },
    {
        "description": "Addition with Object produces NaN",
        "rule": { "+": [{ "val": "x" }, 1] },
        "error": { "type": "NaN" },
        "data": { "x": {} }
    },
    {
        "description": "Plus Operator with Single Operand, Invalid String Produces NaN",
        "rule": { "+": "Hello" },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Array Input Produces NaN",
        "rule": { "+": [[1]] },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Object Input Produces NaN",
        "rule": { "+": [{}] },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Plus Operator with Single Operand, Direct Object Input Produces NaN",
        "rule": { "+": {} },
        "error": { "type": "NaN" },
        "data": null
    }
]