Lines
95.65 %
Functions
100 %
Branches
use crate::ast::{Expr, WasmType};
use crate::compiler::expr::eval_value;
use crate::reader::Reader;
use crate::runtime::SymbolTable;
fn eval_type(src: &str) -> Option<WasmType> {
let expr = Reader::parse_expr(src).expect("parse");
let mut symbols = SymbolTable::with_builtins_for_wasm();
match eval_value(&mut symbols, &expr).expect("eval") {
Expr::WasmRuntime(ty) => Some(ty),
_ => None,
}
#[test]
fn integer_literal_arms_adopt_a_sibling_scalar() {
let ty = eval_type("(cond ((= (entity-count) 5) 1/2) ((= (entity-count) 0) 1) (t 2))");
assert_eq!(ty, Some(WasmType::Ratio));
fn a_nil_arm_rides_a_sibling_list() {
let ty = eval_type(
"(cond ((= (entity-count) 0) (list 1/2)) ((= (entity-count) 5) (progn (entity-count) nil)))",
);
assert!(matches!(ty, Some(WasmType::PairRef(_))), "got {ty:?}");
fn a_diverging_final_clause_adds_no_arm_like_an_if() {
let cond = eval_type("(block b (cond ((= (entity-count) 5) 1/2) (t (return-from b 4))))");
let branch = eval_type("(block b (if (= (entity-count) 5) 1/2 (return-from b 4)))");
assert_eq!(branch, Some(WasmType::Ratio));
assert_eq!(cond, branch);