Fork of daniellemaywood.uk/gleam — Wasm codegen work
2.4 kB
169 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 The Gleam contributors
3
4use crate::assert_erl;
5
6#[test]
7fn function_as_value() {
8 assert_erl!(
9 r#"
10fn other() {
11 Nil
12}
13
14pub fn main() {
15 other
16}
17"#
18 );
19}
20
21#[test]
22fn nested_imported_function_as_value() {
23 assert_erl!(
24 ("package", "some/other", "pub fn wibble() { Nil }"),
25 r#"
26import some/other
27
28pub fn main() {
29 other.wibble
30}
31"#
32 );
33}
34
35#[test]
36fn nested_unqualified_imported_function_as_value() {
37 assert_erl!(
38 ("package", "some/other", "pub fn wibble() { Nil }"),
39 r#"
40import some/other.{wibble}
41
42pub fn main() {
43 wibble
44}
45"#
46 );
47}
48
49#[test]
50fn nested_aliased_imported_function_as_value() {
51 assert_erl!(
52 ("package", "some/other", "pub fn wibble() { Nil }"),
53 r#"
54import some/other.{wibble as wobble}
55
56pub fn main() {
57 wobble
58}
59"#
60 );
61}
62
63#[test]
64fn function_called() {
65 assert_erl!(
66 r#"
67pub fn main() {
68 main()
69}
70"#
71 );
72}
73
74#[test]
75fn nested_imported_function_called() {
76 assert_erl!(
77 ("package", "some/other", "pub fn wibble() { Nil }"),
78 r#"
79import some/other
80
81pub fn main() {
82 other.wibble()
83}
84"#
85 );
86}
87
88#[test]
89fn nested_unqualified_imported_function_called() {
90 assert_erl!(
91 ("package", "some/other", "pub fn wibble() { Nil }"),
92 r#"
93import some/other.{wibble}
94
95pub fn main() {
96 wibble()
97}
98"#
99 );
100}
101
102#[test]
103fn nested_aliased_imported_function_called() {
104 assert_erl!(
105 ("package", "some/other", "pub fn wibble() { Nil }"),
106 r#"
107import some/other.{wibble as wobble}
108
109pub fn main() {
110 wobble()
111}
112"#
113 );
114}
115
116#[test]
117fn labelled_argument_ordering() {
118 // https://github.com/gleam-lang/gleam/issues/3671
119 assert_erl!(
120 "
121type A { A }
122type B { B }
123type C { C }
124type D { D }
125
126fn wibble(a a: A, b b: B, c c: C, d d: D) {
127 Nil
128}
129
130pub fn main() {
131 wibble(A, C, D, b: B)
132 wibble(A, C, D, b: B)
133 wibble(B, C, D, a: A)
134 wibble(B, C, a: A, d: D)
135 wibble(B, C, d: D, a: A)
136 wibble(B, D, a: A, c: C)
137 wibble(B, D, c: C, a: A)
138 wibble(C, D, b: B, a: A)
139}
140"
141 );
142}
143
144#[test]
145fn unused_private_functions() {
146 assert_erl!(
147 r#"
148pub fn main() -> Int {
149 used()
150}
151
152fn used() -> Int {
153 123
154}
155
156fn unused1() -> Int {
157 unused2()
158}
159
160fn unused2() -> Int {
161 used()
162}
163
164fn unused3() -> Int {
165 used()
166}
167"#
168 );
169}