Lines
94.29 %
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))]
//! `1+` / `1-` over a runtime argument lower like `(+ x 1)` / `(- x 1)`.
use nms::interpreter::Interpreter;
use scripting::nomiscript::format_value;
fn printed(src: &str) -> String {
let mut interp = Interpreter::new(false).unwrap();
let results = interp
.eval(src)
.unwrap_or_else(|e| panic!("eval {src:?}: {e}"));
let value = results
.into_iter()
.next_back()
.unwrap_or_else(|| panic!("eval {src:?} produced no value"));
format_value(&value)
}
#[test]
fn a_runtime_index_steps_by_one() {
assert_eq!(
printed("(let ((g 0)) (dolist (y '(2)) (setf g y)) (list (1+ g) (1- g)))"),
"(3 1)"
);
fn a_host_index_steps_by_one() {
printed("(list (1+ (entity-count)) (1- (entity-count)))"),
"(1 -1)"
fn a_runtime_ratio_is_not_stepped_by_an_index() {
let source = "(let ((g 1/2)) (dolist (y '(3/2)) (setf g y)) (list (1+ g) (1- g)))";
let refused = Interpreter::new(false)
.unwrap()
.eval(source)
.expect_err("a mix, CL (5/2 1/2)");
assert!(
refused
.to_string()
.contains("+ cannot mix an index (count) with a scalar"),
"{refused}"
fn a_literal_argument_still_folds() {
assert_eq!(printed("(list (1+ 5) (1- 5))"), "(6 4)");