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>
| Changeset | 808a4610acbc9ad0c02b8dee78220e29ffa6b57b |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | c3e08c2ac5b3 |
| Children | |
| Pushlog | by timo via ssh |
modified crates/feel-core/tests/fixtures_test.rs +17 −2
| @@ -4,11 +4,16 @@ | ||
| 4 | 4 | //! Every fixture case is asserted according to its `comparison` mode: |
| 5 | 5 | //! * `exact` -> structural equality |
| 6 | 6 | //! * `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. | |
| 7 | 12 | |
| 8 | 13 | use std::fs; |
| 9 | 14 | use std::path::{Path, PathBuf}; |
| 10 | 15 | |
| 11 | -use feel_core::{evaluate, Context, Value}; | |
| 16 | +use feel_core::{coerce, evaluate, parse_type, Context, Value}; | |
| 12 | 17 | |
| 13 | 18 | fn fixtures_dir() -> PathBuf { |
| 14 | 19 | Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures") |
| @@ -70,9 +75,19 @@ | ||
| 70 | 75 | let ctx = context_from_case(case, id); |
| 71 | 76 | // Collapse error provenance: TCK expectations are spec-shaped (a type error |
| 72 | 77 | // is just `null`), so we compare against the lenient view (ADR-14). |
| 73 | - let got = evaluate(expr, &ctx) | |
| 78 | + let evaluated = evaluate(expr, &ctx) | |
| 74 | 79 | .unwrap_or_else(|e| panic!("[{id}] evaluating `{expr}` failed: {e}")) |
| 75 | 80 | .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 | + }; | |
| 76 | 91 | |
| 77 | 92 | match comparison { |
| 78 | 93 | "exact" => { |