1
use crate::ast::{Expr, WasmType};
2
use crate::compiler::expr::eval_value;
3
use crate::reader::Reader;
4
use crate::runtime::SymbolTable;
5

            
6
4
fn eval_type(src: &str) -> Option<WasmType> {
7
4
    let expr = Reader::parse_expr(src).expect("parse");
8
4
    let mut symbols = SymbolTable::with_builtins_for_wasm();
9
4
    match eval_value(&mut symbols, &expr).expect("eval") {
10
4
        Expr::WasmRuntime(ty) => Some(ty),
11
        _ => None,
12
    }
13
4
}
14

            
15
#[test]
16
1
fn integer_literal_arms_adopt_a_sibling_scalar() {
17
1
    let ty = eval_type("(cond ((= (entity-count) 5) 1/2) ((= (entity-count) 0) 1) (t 2))");
18
1
    assert_eq!(ty, Some(WasmType::Ratio));
19
1
}
20

            
21
#[test]
22
1
fn a_nil_arm_rides_a_sibling_list() {
23
1
    let ty = eval_type(
24
1
        "(cond ((= (entity-count) 0) (list 1/2)) ((= (entity-count) 5) (progn (entity-count) nil)))",
25
1
    );
26
1
    assert!(matches!(ty, Some(WasmType::PairRef(_))), "got {ty:?}");
27
1
}
28

            
29
#[test]
30
1
fn a_diverging_final_clause_adds_no_arm_like_an_if() {
31
1
    let cond = eval_type("(block b (cond ((= (entity-count) 5) 1/2) (t (return-from b 4))))");
32
1
    let branch = eval_type("(block b (if (= (entity-count) 5) 1/2 (return-from b 4)))");
33
1
    assert_eq!(branch, Some(WasmType::Ratio));
34
1
    assert_eq!(cond, branch);
35
1
}