43 lines
705 B
Rust
43 lines
705 B
Rust
use crate::parser::*;
|
|
|
|
fn test(src: &str, expected: &str) {
|
|
assert_eq!(
|
|
parse(src)
|
|
.into_iter()
|
|
.map(|stmt| format!("{stmt}"))
|
|
.collect::<Vec<_>>()
|
|
.join(";\n"),
|
|
expected.trim(),
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn double() {
|
|
test(
|
|
"
|
|
fn double([x]) (
|
|
^x = x * 2;
|
|
)
|
|
",
|
|
"(set! double (fn ([x] [x]) (^x = (x * 2))))",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn make_counter() {
|
|
test(
|
|
"
|
|
fn make_counter([] [inc]) (
|
|
i = 0;
|
|
^inc = fn([] [i]) (
|
|
i = i + 1;
|
|
^i = i;
|
|
);
|
|
|
|
# or fn ^inc(...)
|
|
)
|
|
",
|
|
"(set! make_counter (fn ([] [inc]) (i = 0) (^inc = (fn ([] [i]) (i = (i + 1)) (^i = i)))))",
|
|
);
|
|
}
|