Lines
100 %
Functions
Branches
//! Runtime behavior of the universal nomiscript prelude (ADR-0029).
//!
//! The prelude math:* / list:* helpers are auto-loaded into `with_builtins()`,
//! so these forms eval without defining anything. Pure-constant calls
//! const-fold through the eval path, exercising the helper bodies directly.
use nomiscript::{
Reader, eval_program,
runtime::{SymbolTable, Value},
};
fn eval_expr(code: &str) -> Result<Value, nomiscript::Error> {
let program = Reader::parse(code)?;
let mut symbols = SymbolTable::with_builtins();
eval_program(&mut symbols, &program)
}
fn num(n: i64) -> Value {
Value::Number(num_rational::Ratio::from_integer(n))
#[test]
fn math_square_computes() {
assert_eq!(eval_expr("(math:square 7)").expect("square"), num(49));
fn math_cube_computes() {
assert_eq!(eval_expr("(math:cube 3)").expect("cube"), num(27));
fn list_second_extracts() {
assert_eq!(
eval_expr("(list:second (list 10 20 30))").expect("second"),
num(20)
);
fn list_third_extracts() {
eval_expr("(list:third (list 10 20 30))").expect("third"),
num(30)