Skip to content

Commit 9b13594

Browse files
Remove old "compile" function and make tests call new compile_module
1 parent 2fdbec8 commit 9b13594

8 files changed

+225
-118
lines changed

src/compiler.gleam

-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ import gleam/option
88
import gleam/result
99
import gleam/string
1010

11-
// called only by unit tests
12-
// todo: remove
13-
pub fn compile(module_contents: String) -> Result(String, glance.Error) {
14-
module_contents
15-
|> glance.module
16-
|> result.map(transformer.transform)
17-
|> result.map(generator.generate)
18-
}
19-
2011
pub fn compile_module(glance_module: glance.Module) -> String {
2112
glance_module
2213
|> transformer.transform

test/compiler/assignment_test.gleam

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import compiler
2+
import glance
23
import gleeunit/should
34

45
pub fn simple_assignment_test() {
56
"pub fn main() {
67
let a = \"hello world\"
78
}
89
"
9-
|> compiler.compile
10+
|> glance.module
1011
|> should.be_ok
12+
|> compiler.compile_module
1113
|> should.equal(
1214
"from gleam_builtins import *
1315
@@ -22,8 +24,9 @@ pub fn mulitple_simple_assignment_test() {
2224
let b = 42
2325
}
2426
"
25-
|> compiler.compile
27+
|> glance.module
2628
|> should.be_ok
29+
|> compiler.compile_module
2730
|> should.equal(
2831
"from gleam_builtins import *
2932

test/compiler/bitstring_test.gleam

+37-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import compiler
2+
import glance
23
import gleeunit/should
34

45
pub fn single_byte_case_test() {
56
"pub fn main() {
67
<<16>>
78
}
89
"
9-
|> compiler.compile
10+
|> glance.module
1011
|> should.be_ok
12+
|> compiler.compile_module
1113
|> should.equal(
1214
"from gleam_builtins import *
1315
@@ -21,8 +23,9 @@ pub fn multiple_bytes_case_test() {
2123
<<16, 42, 255>>
2224
}
2325
"
24-
|> compiler.compile
26+
|> glance.module
2527
|> should.be_ok
28+
|> compiler.compile_module
2629
|> should.equal(
2730
"from gleam_builtins import *
2831
@@ -36,8 +39,9 @@ pub fn two_byte_integers_test() {
3639
<<62_000:16, 63_000:16>>
3740
}
3841
"
39-
|> compiler.compile
42+
|> glance.module
4043
|> should.be_ok
44+
|> compiler.compile_module
4145
|> should.equal(
4246
"from gleam_builtins import *
4347
@@ -52,8 +56,9 @@ pub fn size_expression_test() {
5256
<<62_000:size(x)>>
5357
}
5458
"
55-
|> compiler.compile
59+
|> glance.module
5660
|> should.be_ok
61+
|> compiler.compile_module
5762
|> should.equal(
5863
"from gleam_builtins import *
5964
@@ -68,8 +73,9 @@ pub fn little_endian_test() {
6873
<<4_666_000:32-little>>
6974
}
7075
"
71-
|> compiler.compile
76+
|> glance.module
7277
|> should.be_ok
78+
|> compiler.compile_module
7379
|> should.equal(
7480
"from gleam_builtins import *
7581
@@ -83,8 +89,9 @@ pub fn big_endian_test() {
8389
<<4_666_000:32-big>>
8490
}
8591
"
86-
|> compiler.compile
92+
|> glance.module
8793
|> should.be_ok
94+
|> compiler.compile_module
8895
|> should.equal(
8996
"from gleam_builtins import *
9097
@@ -98,8 +105,9 @@ pub fn native_endian_test() {
98105
<<4_666_000:32-native>>
99106
}
100107
"
101-
|> compiler.compile
108+
|> glance.module
102109
|> should.be_ok
110+
|> compiler.compile_module
103111
|> should.equal(
104112
"from gleam_builtins import *
105113
@@ -113,8 +121,9 @@ pub fn size_unit_test() {
113121
<<64_003:2-unit(8)>>
114122
}
115123
"
116-
|> compiler.compile
124+
|> glance.module
117125
|> should.be_ok
126+
|> compiler.compile_module
118127
|> should.equal(
119128
"from gleam_builtins import *
120129
@@ -128,8 +137,9 @@ pub fn float_default_double_test() {
128137
<<64.888889:float>>
129138
}
130139
"
131-
|> compiler.compile
140+
|> glance.module
132141
|> should.be_ok
142+
|> compiler.compile_module
133143
|> should.equal(
134144
"from gleam_builtins import *
135145
@@ -143,8 +153,9 @@ pub fn float_explicit_double_test() {
143153
<<64.888889:64-float>>
144154
}
145155
"
146-
|> compiler.compile
156+
|> glance.module
147157
|> should.be_ok
158+
|> compiler.compile_module
148159
|> should.equal(
149160
"from gleam_builtins import *
150161
@@ -158,8 +169,9 @@ pub fn float_explicit_single_test() {
158169
<<64.888889:32-float>>
159170
}
160171
"
161-
|> compiler.compile
172+
|> glance.module
162173
|> should.be_ok
174+
|> compiler.compile_module
163175
|> should.equal(
164176
"from gleam_builtins import *
165177
@@ -173,8 +185,9 @@ pub fn float_single_little_test() {
173185
<<64.888889:32-float>>
174186
}
175187
"
176-
|> compiler.compile
188+
|> glance.module
177189
|> should.be_ok
190+
|> compiler.compile_module
178191
|> should.equal(
179192
"from gleam_builtins import *
180193
@@ -188,8 +201,9 @@ pub fn explicit_int_test() {
188201
<<42:int>>
189202
}
190203
"
191-
|> compiler.compile
204+
|> glance.module
192205
|> should.be_ok
206+
|> compiler.compile_module
193207
|> should.equal(
194208
"from gleam_builtins import *
195209
@@ -206,8 +220,9 @@ pub fn bitstring_test() {
206220
<<<<3>>:bit_string>>
207221
}
208222
"
209-
|> compiler.compile
223+
|> glance.module
210224
|> should.be_ok
225+
|> compiler.compile_module
211226
|> should.equal(
212227
"from gleam_builtins import *
213228
@@ -221,8 +236,9 @@ pub fn u8_test() {
221236
<<\"hello\":utf8>>
222237
}
223238
"
224-
|> compiler.compile
239+
|> glance.module
225240
|> should.be_ok
241+
|> compiler.compile_module
226242
|> should.equal(
227243
"from gleam_builtins import *
228244
@@ -236,8 +252,9 @@ pub fn u16_test() {
236252
<<\"hello\":utf16>>
237253
}
238254
"
239-
|> compiler.compile
255+
|> glance.module
240256
|> should.be_ok
257+
|> compiler.compile_module
241258
|> should.equal(
242259
"from gleam_builtins import *
243260
@@ -251,8 +268,9 @@ pub fn u32_test() {
251268
<<\"hello\":utf32>>
252269
}
253270
"
254-
|> compiler.compile
271+
|> glance.module
255272
|> should.be_ok
273+
|> compiler.compile_module
256274
|> should.equal(
257275
"from gleam_builtins import *
258276
@@ -266,8 +284,9 @@ pub fn u32_little_test() {
266284
<<\"hello\":utf32-little>>
267285
}
268286
"
269-
|> compiler.compile
287+
|> glance.module
270288
|> should.be_ok
289+
|> compiler.compile_module
271290
|> should.equal(
272291
"from gleam_builtins import *
273292

0 commit comments

Comments
 (0)