fsm-guards 0.1.1

Fuel-metered JSONLogic guard evaluation with per-call custom operators — forked from jsonlogic-rs
Documentation
use fsm_guards::EvalCtx;
use serde_json::{json, Value};
use std::sync::Arc;

#[test]
fn default_fuel_is_200() {
    let ctx = EvalCtx::new();
    assert_eq!(ctx.fuel, 200);
}

#[test]
fn with_fuel_overrides() {
    let ctx = EvalCtx::new().with_fuel(50);
    assert_eq!(ctx.fuel, 50);
}

#[test]
fn with_op_registers() {
    let ctx = EvalCtx::new().with_op("always_true", |_args: &[Value]| {
        Ok(Value::Bool(true))
    });
    assert!(ctx.ops.contains_key("always_true"));
}

#[test]
fn evalctx_is_send_sync() {
    fn assert_send_sync<T: Send + Sync>() {}
    assert_send_sync::<EvalCtx>();
}

#[test]
fn evalctx_default_is_default_trait() {
    let ctx: EvalCtx = Default::default();
    assert_eq!(ctx.fuel, 200);
    assert!(ctx.ops.is_empty());
}

#[test]
fn evalctx_sharable_via_arc() {
    let ctx = Arc::new(EvalCtx::new().with_fuel(42));
    let ctx2 = Arc::clone(&ctx);
    let handle = std::thread::spawn(move || ctx2.fuel);
    assert_eq!(handle.join().unwrap(), 42);
}