Fork of daniellemaywood.uk/gleam — Wasm codegen work
1.9 kB
167 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2025 The Gleam contributors
3
4use crate::assert_erl;
5
6#[test]
7fn assert_variable() {
8 assert_erl!(
9 "
10pub fn main() {
11 let x = True
12 assert x
13}
14"
15 );
16}
17
18#[test]
19fn assert_literal() {
20 assert_erl!(
21 "
22pub fn main() {
23 assert False
24}
25"
26 );
27}
28
29#[test]
30fn assert_binary_operation() {
31 assert_erl!(
32 "
33pub fn main() {
34 let x = True
35 assert x || False
36}
37"
38 );
39}
40
41#[test]
42fn assert_binary_operation2() {
43 assert_erl!(
44 "
45pub fn eq(a, b) {
46 assert a == b
47}
48"
49 );
50}
51
52#[test]
53fn assert_binary_operation3() {
54 assert_erl!(
55 "
56pub fn assert_answer(x) {
57 assert x == 42
58}
59"
60 );
61}
62
63#[test]
64fn assert_function_call() {
65 assert_erl!(
66 "
67fn bool() {
68 True
69}
70
71pub fn main() {
72 assert bool()
73}
74"
75 );
76}
77
78#[test]
79fn assert_function_call2() {
80 assert_erl!(
81 "
82fn and(a, b) {
83 a && b
84}
85
86pub fn go(x) {
87 assert and(True, x)
88}
89"
90 );
91}
92
93#[test]
94fn assert_nested_function_call() {
95 assert_erl!(
96 "
97fn and(x, y) {
98 x && y
99}
100
101pub fn main() {
102 assert and(and(True, False), True)
103}
104"
105 );
106}
107
108#[test]
109fn assert_binary_operator_with_side_effects() {
110 assert_erl!(
111 "
112fn wibble(a, b) {
113 let result = a + b
114 result == 10
115}
116
117pub fn go(x) {
118 assert True && wibble(1, 4)
119}
120"
121 );
122}
123
124#[test]
125fn assert_binary_operator_with_side_effects2() {
126 assert_erl!(
127 "
128fn wibble(a, b) {
129 let result = a + b
130 result == 10
131}
132
133pub fn go(x) {
134 assert wibble(5, 5) && wibble(4, 6)
135}
136"
137 );
138}
139
140#[test]
141fn assert_with_message() {
142 assert_erl!(
143 r#"
144pub fn main() {
145 assert True as "This shouldn't fail"
146}
147"#
148 );
149}
150
151#[test]
152fn assert_with_block_message() {
153 assert_erl!(
154 r#"
155fn identity(a) {
156 a
157}
158
159pub fn main() {
160 assert identity(True) as {
161 let message = identity("This shouldn't fail")
162 message
163 }
164}
165"#
166 );
167}