Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

feat(harness): coerce_to field for §10.3.2.9.4 target-type coercion

public

feat(harness): coerce_to field for §10.3.2.9.4 target-type coercion

Extend fixtures_test.rs with an optional `coerce_to` key (a FEEL type string).
When present, the evaluated result is passed through `coerce(value, &parse_type(...))`
before comparison, modelling the decision-variable / literal-expression `typeRef`
boundary that 0082-feel-coercion exercises.  Existing fixtures carry no `coerce_to`
and are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changeset808a4610acbc9ad0c02b8dee78220e29ffa6b57b
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parentsc3e08c2ac5b3
Children
Pushlog
by timo via ssh

modified crates/feel-core/tests/fixtures_test.rs +17 −2

@@ -4,11 +4,16 @@
44
 //! Every fixture case is asserted according to its `comparison` mode:
55
 //!   * `exact`       -> structural equality
66
 //!   * `f64_epsilon` -> numeric tolerance (our documented decimal128->f64 deviation)
7
+//!
8
+//! An optional `coerce_to` field (a FEEL type string, e.g. `"string"`,
9
+//! `"list<number>"`) triggers §10.3.2.9.4 implicit conversion of the evaluated
10
+//! result before comparison.  This models the decision-variable / literal-expression
11
+//! `typeRef` coercion that the 0082-feel-coercion suite exercises.
712
 
813
 use std::fs;
914
 use std::path::{Path, PathBuf};
1015
 
11
-use feel_core::{evaluate, Context, Value};
16
+use feel_core::{coerce, evaluate, parse_type, Context, Value};
1217
 
1318
 fn fixtures_dir() -> PathBuf {
1419
     Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures")
@@ -70,9 +75,19 @@
7075
     let ctx = context_from_case(case, id);
7176
     // Collapse error provenance: TCK expectations are spec-shaped (a type error
7277
     // is just `null`), so we compare against the lenient view (ADR-14).
73
-    let got = evaluate(expr, &ctx)
78
+    let evaluated = evaluate(expr, &ctx)
7479
         .unwrap_or_else(|e| panic!("[{id}] evaluating `{expr}` failed: {e}"))
7580
         .into_lenient();
81
+
82
+    // Optional §10.3.2.9.4 coercion: apply when the fixture carries a target type
83
+    // (models the decision-variable / literal-expression `typeRef` boundary).
84
+    let got = if let Some(type_str) = case["coerce_to"].as_str() {
85
+        let ty = parse_type(type_str)
86
+            .unwrap_or_else(|| panic!("[{id}] unparseable coerce_to: {type_str:?}"));
87
+        coerce(evaluated, &ty)
88
+    } else {
89
+        evaluated
90
+    };
7691
 
7792
     match comparison {
7893
         "exact" => {