1
use super::*;
2
use crate::reader::Reader;
3

            
4
2
fn body_calls_self(body: &str) -> bool {
5
2
    let ctx = CompileContext::new_with_host_fns(&[]).expect("context");
6
2
    let body = Reader::parse_expr(body).expect("parse");
7
2
    body_calls_inlining_or_self(&ctx, "F", &body)
8
2
}
9

            
10
#[test]
11
1
fn a_self_call_under_a_template_quote_is_found() {
12
1
    assert!(body_calls_self("`(a ',(f 1))"));
13
1
}
14

            
15
#[test]
16
1
fn a_self_call_in_template_data_is_not_found() {
17
1
    assert!(!body_calls_self("`(a (f 1))"));
18
1
}
19

            
20
#[test]
21
1
fn an_any_parameter_takes_the_typed_list_its_argument_compiles_to() {
22
1
    let mut ctx = CompileContext::new_with_host_fns(&[]).expect("context");
23
1
    let mut emit = FunctionEmitter::new();
24
1
    let mut symbols = SymbolTable::with_builtins_for_wasm();
25
1
    let arg = Reader::parse_expr("(list (lambda () 8))").expect("parse");
26
1
    emit_runtime_call(
27
1
        &mut ctx,
28
1
        &mut emit,
29
1
        &mut symbols,
30
1
        &[arg],
31
1
        &[WasmType::AnyRef],
32
1
        &MonomorphEntry {
33
1
            func_idx: 0,
34
1
            ret_ty: WasmType::AnyRef,
35
1
            slots: Vec::new(),
36
1
        },
37
1
    )
38
1
    .expect("an any parameter takes any value");
39
1
}
40

            
41
#[test]
42
1
fn a_typed_parameter_still_refuses_another_type() {
43
1
    let mut ctx = CompileContext::new_with_host_fns(&[]).expect("context");
44
1
    let mut emit = FunctionEmitter::new();
45
1
    let mut symbols = SymbolTable::with_builtins_for_wasm();
46
1
    let arg = Reader::parse_expr("(list (lambda () 8))").expect("parse");
47
1
    let err = emit_runtime_call(
48
1
        &mut ctx,
49
1
        &mut emit,
50
1
        &mut symbols,
51
1
        &[arg],
52
1
        &[WasmType::Ratio],
53
1
        &MonomorphEntry {
54
1
            func_idx: 0,
55
1
            ret_ty: WasmType::Ratio,
56
1
            slots: Vec::new(),
57
1
        },
58
1
    )
59
1
    .expect_err("mismatch");
60
1
    assert!(err.to_string().contains("argument type mismatch"), "{err}");
61
1
}