Fork of daniellemaywood.uk/gleam — Wasm codegen work
2.7 kB
212 lines
1use crate::assert_source_map;
2
3#[test]
4fn sourcemap_function_definition() {
5 assert_source_map!(
6 "
7/// my add function
8pub fn add_2(x) {
9 x + 2
10}"
11 )
12}
13
14#[test]
15fn sourcemap_function_definition_with_variable_assignment() {
16 assert_source_map!(
17 "
18/// my function
19pub fn wibble() {
20 let wibble = 1
21 wibble + 2
22}"
23 )
24}
25
26#[test]
27fn sourcemap_function_definition_with_string_with_newline_escaped() {
28 assert_source_map!(
29 "
30/// my function
31pub fn wibble() {
32 let wibble = \"hello\\nworld\"
33 wibble <> \"!\"
34}"
35 )
36}
37
38#[test]
39fn sourcemap_function_definition_with_string_with_newline() {
40 assert_source_map!(
41 "
42/// my function
43pub fn wibble() {
44 let wibble = \"hello
45world\"
46 wibble <> \"!\"
47}"
48 )
49}
50
51#[test]
52fn sourcemap_custom_type_definition() {
53 assert_source_map!(
54 "
55/// my custom type
56pub type Wibble {
57 /// Wibble
58 Wibble
59 /// Wobble
60 Wobble(field: Int)
61 /// Wabble
62 Wabble(Wibble)
63}"
64 )
65}
66
67#[test]
68fn sourcemap_module_constant() {
69 assert_source_map!(
70 "
71/// my constant
72pub const wibble = 1
73/// wobble
74const wobble = 2
75/// wabble
76pub const wabble = 3"
77 )
78}
79
80#[test]
81fn sourcemap_assert() {
82 assert_source_map!(
83 "
84pub fn main() {
85 let x = True
86 assert x
87}
88"
89 )
90}
91
92#[test]
93fn sourcemap_let_assert() {
94 assert_source_map!(
95 r#"
96pub fn go(x) {
97 let assert #(wibble, wobble) = x
98}
99"#
100 )
101}
102
103#[test]
104fn sourcemap_case_destructure_assignment_statement() {
105 assert_source_map!(
106 "
107pub type Wibble {
108 Wibble(Int, Int)
109}
110
111pub fn go(x) {
112 case Wibble(1, 2) {
113 Wibble(wibble, wobble) -> wibble + wobble
114 }
115}
116"
117 )
118}
119
120#[test]
121fn sourcemap_with_complex_case_expression() {
122 assert_source_map!(
123 "
124pub fn go(one, other) {
125 case one, other {
126 Ok(1), Error(_) -> 1
127 Ok(_), _ -> 2
128 Error(_), Ok(2) -> 3
129 _, _ -> 4
130 }
131}
132"
133 )
134}
135
136#[test]
137fn sourcemap_pipe() {
138 assert_source_map!(
139 "
140fn add_2(x) {
141 x + 2
142}
143
144pub fn go(x) {
145 x |> add_2
146}
147"
148 )
149}
150
151#[test]
152fn sourcemap_use() {
153 assert_source_map!(
154 "
155fn add_3_to_result(i, f) {
156 f(i) + 3
157}
158
159pub fn go(x) {
160 use a <- add_3_to_result(1)
161 a + 2
162}
163"
164 )
165}
166
167#[test]
168fn sourcemap_with_list() {
169 assert_source_map!(
170 "
171pub fn go(x) {
172 [1, 2, 3]
173}
174"
175 )
176}
177
178#[test]
179fn sourcemap_with_tuple() {
180 assert_source_map!(
181 "
182pub fn go(x) {
183 #(1, 2, 3)
184}
185"
186 )
187}
188
189#[test]
190fn sourcemap_with_bitarray() {
191 assert_source_map!(
192 "
193pub fn go(x) {
194 <<256:int>>
195}
196"
197 )
198}
199
200#[test]
201fn sourcemap_with_tail_recursive_functions() {
202 assert_source_map!(
203 "
204pub fn wibble(lon, acc) {
205 case lon {
206 [] -> 0
207 [n, ..rest] -> wibble(rest, acc + n)
208 }
209}
210"
211 )
212}