Fork of daniellemaywood.uk/gleam — Wasm codegen work
874 B
64 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Gleam contributors
3
4use crate::assert_js;
5
6#[test]
7fn tco() {
8 assert_js!(
9 r#"
10pub fn main(x) {
11 case x {
12 0 -> Nil
13 _ -> main(x - 1)
14 }
15}
16"#
17 );
18}
19
20#[test]
21fn tco_case_block() {
22 assert_js!(
23 r#"
24pub fn main(x) {
25 case x {
26 0 -> Nil
27 _ -> {
28 let y = x
29 main(y - 1)
30 }
31 }
32}
33"#
34 );
35}
36
37// https://github.com/gleam-lang/gleam/issues/1779
38#[test]
39fn not_tco_due_to_assignment() {
40 assert_js!(
41 r#"
42pub fn main(x) {
43 let z = {
44 let y = x
45 main(y - 1)
46 }
47 z
48}
49"#
50 );
51}
52
53// https://github.com/gleam-lang/gleam/issues/2400
54#[test]
55fn shadowing_so_not_recursive() {
56 // This funtion is calling an argument with the same name as itself, so it is not recursive
57 assert_js!(
58 r#"
59pub fn map(map) {
60 map()
61}
62"#
63 );
64}