Fork of daniellemaywood.uk/gleam — Wasm codegen work
1.7 kB
114 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2021 The Gleam contributors
3
4use crate::assert_erl;
5
6#[test]
7fn shadow_let() {
8 // https://github.com/gleam-lang/gleam/issues/333
9 assert_erl!(
10 r#"
11pub fn go(a) {
12 case a {
13 99 -> {
14 let a = a
15 1
16 }
17 _ -> a
18 }
19}"#
20 );
21}
22
23#[test]
24fn shadow_param() {
25 // https://github.com/gleam-lang/gleam/issues/772
26 assert_erl!(
27 "pub fn main(board) {
28fn(board) { board }
29 board
30}"
31 );
32}
33
34#[test]
35fn shadow_and_call() {
36 // https://github.com/gleam-lang/gleam/issues/762
37 assert_erl!(
38 r#"
39pub fn main(x) {
40 fn(x) { x }(x)
41}
42"#
43 );
44}
45
46#[test]
47fn shadow_pipe() {
48 assert_erl!(
49 r#"
50pub fn main(x) {
51 x
52 |> fn(x) { x }
53}
54"#
55 );
56}
57
58#[test]
59fn discarded() {
60 // https://github.com/gleam-lang/gleam/issues/788
61 assert_erl!(
62 r#"pub fn go() {
63 let _r = 1
64 let _r = 2
65 Nil
66}"#
67 );
68}
69
70#[test]
71fn anon_external_fun_name_escaping() {
72 // https://github.com/gleam-lang/gleam/issues/1418
73 assert_erl!(
74 r#"
75@external(erlang, "one.two", "three.four")
76fn func() -> Nil
77
78pub fn main() {
79 func
80}"#
81 );
82}
83
84#[test]
85fn module_const_vars() {
86 assert_erl!(
87 "const int = 42
88const int_alias = int
89pub fn use_int_alias() { int_alias }
90
91fn int_identity(i: Int) { i }
92const int_identity_alias: fn(Int) -> Int = int_identity
93pub fn use_int_identity_alias() { int_identity_alias(42) }
94
95const compound: #(Int, fn(Int) -> Int, fn(Int) -> Int) = #(int, int_identity, int_identity_alias)
96pub fn use_compound() { compound.1(compound.0) }
97"
98 )
99}
100
101#[test]
102fn blocks_are_scopes() {
103 assert_erl!(
104 "
105pub fn main() {
106 let x = 1
107 {
108 let x = 2
109 }
110 x
111}
112"
113 )
114}