Fork of daniellemaywood.uk/gleam — Wasm codegen work
887 B
87 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Gleam contributors
3
4use crate::assert_js;
5
6#[test]
7fn arity_1() {
8 assert_js!(
9 r#"
10pub fn main() {
11 use <- pair()
12 123
13}
14
15fn pair(f) {
16 let x = f()
17 #(x, x)
18}
19"#,
20 )
21}
22
23#[test]
24fn arity_2() {
25 assert_js!(
26 r#"
27pub fn main() {
28 use <- pair(1.0)
29 123
30}
31
32fn pair(x, f) {
33 let y = f()
34 #(x, y)
35}
36"#,
37 )
38}
39
40#[test]
41fn arity_3() {
42 assert_js!(
43 r#"
44pub fn main() {
45 use <- trip(1.0, "")
46 123
47}
48
49fn trip(x, y, f) {
50 let z = f()
51 #(x, y, z)
52}
53"#,
54 )
55}
56
57#[test]
58fn no_callback_body() {
59 assert_js!(
60 r#"
61pub fn main() {
62 let thingy = fn(f) { f() }
63 use <- thingy()
64}
65"#
66 );
67}
68
69#[test]
70fn patterns() {
71 assert_js!(
72 r#"
73pub fn main() {
74 use Box(x) <- apply(Box(1))
75 x
76}
77
78type Box(a) {
79 Box(a)
80}
81
82fn apply(arg, fun) {
83 fun(arg)
84}
85"#
86 );
87}