-- End-to-end smoke test for the feel-lua loadable module (ADR-22), the Lua -- analogue of feel-wasm/smoke.mjs. Build the module, then point Lua's C path at -- it and run this script: -- -- cargo build -p feel-lua --no-default-features --features lua54,module -- LUA_CPATH='target/debug/lib?.so;;' lua5.4 crates/feel-lua/smoke.lua -- -- (`lib?.so` expands `?` -> `feel`, i.e. `libfeel.so`; no rename needed.) local feel = require("feel") local function eq(actual, expected, label) if actual ~= expected then error(string.format("FAIL %s: expected %s, got %s", label, tostring(expected), tostring(actual))) end print(string.format("ok %-42s = %s", label, tostring(actual))) end -- Scalars, arithmetic, control flow. eq(feel.evaluate("1 + 1"), 2, "1 + 1") eq(feel.evaluate("2 * 3 + 1"), 7, "2 * 3 + 1") eq(feel.evaluate([["foo"]]), "foo", 'string "foo"') eq(feel.evaluate("1 < 2"), true, "1 < 2") -- Lists round-trip as sequence tables. local doubled = feel.evaluate("for i in [1,2,3] return i * 2") eq(table.concat(doubled, ","), "2,4,6", "for-loop list") -- Lazy path access into nested tables (firing __index on demand). eq(feel.evaluate("person.age", { person = { age = 42 } }), 42, "person.age") -- Host callable bound directly in the context. eq(feel.evaluate("f(2, 3)", { f = function(a, b) return a + b end }), 5, "host f(2,3)") -- FEEL named arguments arrive as a single trailing options table. eq( feel.evaluate("f(2, b: 3)", { f = function(a, opts) return a + opts.b end }), 5, "named args -> {b=3}" ) -- Ambient function registry (the third argument). eq(feel.evaluate("add(2, 3)", nil, { add = function(a, b) return a + b end }), 5, "registry add(2,3)") -- A context binding shadows a built-in (host override). eq(feel.evaluate("count([1,2,3])", { count = function(_) return 99 end }), 99, "shadow builtin count") -- Identity pass-through: a table/function handed in comes back unchanged. local obj = { a = 1 } eq(feel.evaluate("o", { o = obj }) == obj, true, "table identity") -- Temporal values cross out as ISO-8601 strings (RD-8). eq(feel.evaluate("date(2020, 1, 15)"), "2020-01-15", "date -> ISO") eq(feel.evaluate([[duration("P1Y2M")]]), "P1Y2M", "duration -> ISO") -- Error semantics: a raised host error is an error-null -> nil (lenient). eq(feel.evaluate("f()", { f = function() error("boom") end }), nil, "host error -> nil (lenient)") -- Strict surfaces the error-null as a catchable Lua error. local ok = pcall(function() return feel.evaluate_strict("f()", { f = function() error("boom") end }) end) eq(ok, false, "host error -> raised (strict)") -- A regular `return nil` is a value-null, not an error -> strict does NOT raise. local ok2 = pcall(function() return feel.evaluate_strict("g()", { g = function() return nil end }) end) eq(ok2, true, "return nil -> value-null (strict ok)") -- compile() once, evaluate against many contexts. local prog = feel.compile("a + 1") eq(prog:evaluate({ a = 1 }), 2, "compiled a+1 (a=1)") eq(prog:evaluate({ a = 41 }), 42, "compiled a+1 (a=41)") print("\nall feel-lua smoke checks passed")