Lines
95.24 %
Functions
71.43 %
Branches
100 %
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! A constant folded from an operand the legacy pipeline refuses (a quoted
//! keyword, an arity it diagnoses) is never consumed by an enclosing form: the
//! result matches the legacy pipeline, forced here with `(let () …)`.
use nms::interpreter::Interpreter;
use scripting::nomiscript::Value;
fn eval(src: &str) -> Result<Value, String> {
let mut interp = Interpreter::new(false).map_err(|e| e.to_string())?;
interp
.eval(src)
.map_err(|e| e.to_string())?
.into_iter()
.next_back()
.ok_or_else(|| format!("{src:?} produced no value"))
}
fn legacy(src: &str) -> Result<Value, String> {
eval(&format!("(let () {src})"))
#[test]
fn a_folded_quoted_operand_agrees_with_the_legacy_pipeline() {
let src = "(not (equal '1 1))";
assert_eq!(eval(src), Ok(Value::Nil));
assert_eq!(eval(src), legacy(src));
fn a_folded_operand_keeps_the_legacy_diagnostics() {
{
let (src, needle) = ("(not (=))", "requires at least 1 argument");
let err = eval(src).expect_err(src);
assert!(err.contains(needle), "{src}: {err}");
assert_eq!(Err(err), legacy(src));