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