Lines
96.97 %
Functions
100 %
Branches
use super::*;
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::special::try_emit_lambda_for_value;
fn required_lambda() -> Expr {
Expr::Lambda(
LambdaParams::simple(vec!["a".to_string()]),
Box::new(Expr::Nil),
)
}
fn optional_lambda() -> Expr {
let mut params = LambdaParams::simple(vec!["a".to_string()]);
params.optional.push(("b".to_string(), None));
Expr::Lambda(params, Box::new(Expr::Nil))
#[test]
fn a_required_only_lambda_passes_the_gate() {
assert!(reject_non_v1_lambda(&required_lambda()).is_ok());
fn a_non_lambda_passes_the_gate() {
assert!(reject_non_v1_lambda(&Expr::Nil).is_ok());
fn an_optional_lambda_is_the_structured_error() {
let err = reject_non_v1_lambda(&optional_lambda()).expect_err("non-v1 rejected");
assert_eq!(err.to_string(), non_v1_lambda_error().to_string());
assert!(
err.to_string()
.contains("not yet supported as a first-class wasm closure")
);
fn only_the_v1_shape_is_emitted_as_a_value() {
let mut ctx = CompileContext::new_with_host_fns(&[]).expect("ctx");
let mut emit = FunctionEmitter::new();
let mut symbols = SymbolTable::with_builtins_for_wasm();
let Expr::Lambda(params, body) = optional_lambda() else {
return;
};
let emitted = try_emit_lambda_for_value(&mut ctx, &mut emit, &mut symbols, ¶ms, &body);
assert!(matches!(emitted, Ok(None)));