···
1
1
-
mod bit_string_rename;
2
2
-
mod import_type;
3
3
-
#[cfg(test)]
4
4
-
mod tests;
5
5
-
6
1
use crate::{
7
2
format::{Formatter, Intermediate},
8
3
Error, Result,
···
21
16
let module = parsed.module;
22
17
23
18
// Fix
24
24
-
let module = bit_string_rename::Fixer::fix(module);
25
25
-
let module = import_type::Fixer::fix(module);
19
19
+
// let module = some_fixer_module::Fixer::fix(module);
26
20
27
21
// Format
28
22
let mut buffer = String::new();
···
1
1
-
use crate::{
2
2
-
ast::{
3
3
-
CallArg, Constant, CustomType, Definition, Import, SrcSpan, TypeAlias, TypeAst,
4
4
-
TypeAstConstructor, UntypedConstant, UntypedDefinition, UntypedImport, UntypedModule,
5
5
-
},
6
6
-
ast_folder::{
7
7
-
PatternFolder, TypeAstFolder, UntypedConstantFolder, UntypedExprFolder, UntypedModuleFolder,
8
8
-
},
9
9
-
build::Target,
10
10
-
};
11
11
-
use ecow::EcoString;
12
12
-
13
13
-
#[derive(Debug, Default)]
14
14
-
pub struct Fixer {
15
15
-
prelude_module_import_alias: Option<EcoString>,
16
16
-
bit_string_name: EcoString,
17
17
-
bit_array_name: EcoString,
18
18
-
}
19
19
-
20
20
-
impl Fixer {
21
21
-
pub fn fix(module: UntypedModule) -> UntypedModule {
22
22
-
let mut fixer = Self {
23
23
-
prelude_module_import_alias: None,
24
24
-
bit_string_name: "BitString".into(),
25
25
-
bit_array_name: "BitArray".into(),
26
26
-
};
27
27
-
fixer.fix_module(module)
28
28
-
}
29
29
-
30
30
-
fn fix_module(&mut self, module: UntypedModule) -> UntypedModule {
31
31
-
// Work out what BitString is called in this module
32
32
-
for d in module.definitions.iter() {
33
33
-
self.determine_names(&d.definition);
34
34
-
}
35
35
-
36
36
-
// Fix the module
37
37
-
self.fold_module(module)
38
38
-
}
39
39
-
40
40
-
fn determine_names(&mut self, d: &UntypedDefinition) {
41
41
-
match d {
42
42
-
Definition::Function(_) | Definition::ModuleConstant(_) => (),
43
43
-
44
44
-
Definition::CustomType(CustomType { name, .. })
45
45
-
| Definition::TypeAlias(TypeAlias { alias: name, .. }) => {
46
46
-
if name == "BitString" && self.bit_string_name == "BitString" {
47
47
-
self.bit_string_name = "".into();
48
48
-
}
49
49
-
}
50
50
-
51
51
-
Definition::Import(i) => {
52
52
-
if i.module == "gleam" {
53
53
-
self.prelude_module_import_alias = i.used_name();
54
54
-
} else {
55
55
-
for i in i.unqualified_values.iter().chain(&i.unqualified_types) {
56
56
-
if i.used_name() == "BitString" && self.bit_string_name == "BitString" {
57
57
-
self.bit_string_name = "".into();
58
58
-
}
59
59
-
}
60
60
-
}
61
61
-
}
62
62
-
}
63
63
-
}
64
64
-
}
65
65
-
66
66
-
impl UntypedModuleFolder for Fixer {
67
67
-
fn fold_import(&mut self, mut i: UntypedImport, _target: Option<Target>) -> Import<()> {
68
68
-
if i.module == "gleam" {
69
69
-
i.unqualified_values
70
70
-
.iter_mut()
71
71
-
.chain(&mut i.unqualified_types)
72
72
-
.filter(|i| i.name == "BitString")
73
73
-
.for_each(|i| i.name = "BitArray".into());
74
74
-
}
75
75
-
i
76
76
-
}
77
77
-
}
78
78
-
79
79
-
impl UntypedConstantFolder for Fixer {
80
80
-
fn fold_constant_record(
81
81
-
&mut self,
82
82
-
location: SrcSpan,
83
83
-
module: Option<EcoString>,
84
84
-
name: EcoString,
85
85
-
args: Vec<CallArg<UntypedConstant>>,
86
86
-
) -> UntypedConstant {
87
87
-
let name = if name == self.bit_string_name {
88
88
-
self.bit_array_name.clone()
89
89
-
} else {
90
90
-
name
91
91
-
};
92
92
-
Constant::Record {
93
93
-
location,
94
94
-
module,
95
95
-
name,
96
96
-
args,
97
97
-
tag: (),
98
98
-
typ: (),
99
99
-
field_map: None,
100
100
-
}
101
101
-
}
102
102
-
}
103
103
-
104
104
-
impl UntypedExprFolder for Fixer {}
105
105
-
106
106
-
impl TypeAstFolder for Fixer {
107
107
-
fn fold_type_constructor(&mut self, mut constructor: TypeAstConstructor) -> TypeAst {
108
108
-
if constructor.name == self.bit_string_name {
109
109
-
constructor.name = self.bit_array_name.clone();
110
110
-
}
111
111
-
112
112
-
TypeAst::Constructor(constructor)
113
113
-
}
114
114
-
}
115
115
-
116
116
-
impl PatternFolder for Fixer {}
···
1
1
-
use std::collections::HashMap;
2
2
-
3
3
-
use crate::{
4
4
-
analyse::Inferred,
5
5
-
ast::{
6
6
-
CallArg, Constant, Definition, Pattern, SrcSpan, TypeAst, TypeAstConstructor,
7
7
-
UntypedConstant, UntypedDefinition, UntypedExpr, UntypedImport, UntypedModule,
8
8
-
UntypedPattern,
9
9
-
},
10
10
-
ast_folder::{
11
11
-
PatternFolder, TypeAstFolder, UntypedConstantFolder, UntypedExprFolder, UntypedModuleFolder,
12
12
-
},
13
13
-
};
14
14
-
use ecow::EcoString;
15
15
-
use im::HashSet;
16
16
-
17
17
-
#[derive(Debug, Default)]
18
18
-
pub struct Fixer {
19
19
-
imports: HashMap<EcoString, Imported>,
20
20
-
local_types: HashSet<EcoString>,
21
21
-
local_values: HashSet<EcoString>,
22
22
-
}
23
23
-
24
24
-
impl Fixer {
25
25
-
pub fn fix(module: UntypedModule) -> UntypedModule {
26
26
-
Self::default().fix_module(module)
27
27
-
}
28
28
-
29
29
-
fn fix_module(&mut self, module: UntypedModule) -> UntypedModule {
30
30
-
for d in module.definitions.iter() {
31
31
-
self.register_items(&d.definition);
32
32
-
}
33
33
-
34
34
-
// Determine which imported constructors are used as types and which are
35
35
-
// used as values.
36
36
-
let mut module = self.fold_module(module);
37
37
-
38
38
-
for d in module.definitions.iter_mut() {
39
39
-
if let Definition::Import(ref mut i) = d.definition {
40
40
-
self.fix_import(i);
41
41
-
}
42
42
-
}
43
43
-
44
44
-
module
45
45
-
}
46
46
-
47
47
-
fn register_unqualified_imported_constructors(&mut self, i: &UntypedImport) {
48
48
-
for unqualified in &i.unqualified_values {
49
49
-
let first_char = unqualified.name.chars().next().unwrap_or('a');
50
50
-
if first_char.is_uppercase() {
51
51
-
let data = Imported {
52
52
-
module: i.module.clone(),
53
53
-
used_as_type: false,
54
54
-
used_as_value: false,
55
55
-
};
56
56
-
let _ = self.imports.insert(unqualified.used_name().clone(), data);
57
57
-
}
58
58
-
}
59
59
-
}
60
60
-
61
61
-
fn fix_import(&mut self, import: &mut UntypedImport) {
62
62
-
let existing_types: HashSet<EcoString> = import
63
63
-
.unqualified_types
64
64
-
.iter()
65
65
-
.map(|t| t.used_name().clone())
66
66
-
.collect();
67
67
-
let mut types = vec![];
68
68
-
let mut values = vec![];
69
69
-
70
70
-
for unqualified in import.unqualified_values.drain(..) {
71
71
-
match self.imports.get_mut(unqualified.used_name()) {
72
72
-
Some(i) if i.module == import.module => {
73
73
-
if i.used_as_type && !existing_types.contains(unqualified.used_name()) {
74
74
-
types.push(unqualified.clone());
75
75
-
}
76
76
-
if i.used_as_value {
77
77
-
values.push(unqualified.clone());
78
78
-
}
79
79
-
}
80
80
-
_ => values.push(unqualified),
81
81
-
}
82
82
-
}
83
83
-
84
84
-
import.unqualified_values = values;
85
85
-
for t in types {
86
86
-
import.unqualified_types.push(t);
87
87
-
}
88
88
-
}
89
89
-
90
90
-
fn register_items(&mut self, definition: &UntypedDefinition) {
91
91
-
match definition {
92
92
-
Definition::Function(_) | Definition::ModuleConstant(_) => (),
93
93
-
94
94
-
Definition::TypeAlias(a) => {
95
95
-
let _ = self.local_types.insert(a.alias.clone());
96
96
-
}
97
97
-
98
98
-
Definition::CustomType(c) => {
99
99
-
let _ = self.local_types.insert(c.name.clone());
100
100
-
for c in &c.constructors {
101
101
-
let _ = self.local_values.insert(c.name.clone());
102
102
-
}
103
103
-
}
104
104
-
105
105
-
Definition::Import(i) => self.register_unqualified_imported_constructors(i),
106
106
-
}
107
107
-
}
108
108
-
}
109
109
-
110
110
-
impl UntypedModuleFolder for Fixer {}
111
111
-
112
112
-
impl UntypedConstantFolder for Fixer {
113
113
-
fn fold_constant_record(
114
114
-
&mut self,
115
115
-
location: SrcSpan,
116
116
-
module: Option<EcoString>,
117
117
-
name: EcoString,
118
118
-
args: Vec<CallArg<UntypedConstant>>,
119
119
-
) -> UntypedConstant {
120
120
-
if module.is_none()
121
121
-
&& !(name == "Ok" || name == "Error")
122
122
-
&& !self.local_values.contains(&name)
123
123
-
{
124
124
-
if let Some(import) = self.imports.get_mut(&name) {
125
125
-
import.used_as_value = true;
126
126
-
}
127
127
-
}
128
128
-
Constant::Record {
129
129
-
location,
130
130
-
module,
131
131
-
name,
132
132
-
args,
133
133
-
tag: (),
134
134
-
typ: (),
135
135
-
field_map: None,
136
136
-
}
137
137
-
}
138
138
-
139
139
-
fn fold_constant_var(
140
140
-
&mut self,
141
141
-
location: SrcSpan,
142
142
-
module: Option<EcoString>,
143
143
-
name: EcoString,
144
144
-
) -> UntypedConstant {
145
145
-
if module.is_none() && !self.local_values.contains(&name) {
146
146
-
if let Some(import) = self.imports.get_mut(&name) {
147
147
-
import.used_as_value = true;
148
148
-
}
149
149
-
}
150
150
-
Constant::Var {
151
151
-
location,
152
152
-
module,
153
153
-
name,
154
154
-
constructor: None,
155
155
-
typ: (),
156
156
-
}
157
157
-
}
158
158
-
}
159
159
-
160
160
-
impl UntypedExprFolder for Fixer {
161
161
-
fn fold_var(&mut self, location: SrcSpan, name: EcoString) -> UntypedExpr {
162
162
-
if !(self.local_values.contains(&name) || name == "Ok" || name == "Error") {
163
163
-
if let Some(import) = self.imports.get_mut(&name) {
164
164
-
import.used_as_value = true;
165
165
-
}
166
166
-
}
167
167
-
UntypedExpr::Var { location, name }
168
168
-
}
169
169
-
}
170
170
-
171
171
-
impl TypeAstFolder for Fixer {
172
172
-
fn fold_type_constructor(&mut self, constructor: TypeAstConstructor) -> TypeAst {
173
173
-
let name = &constructor.name;
174
174
-
if constructor.module.is_none()
175
175
-
&& !(name == "Result" || name == "List")
176
176
-
&& !self.local_types.contains(name)
177
177
-
{
178
178
-
if let Some(import) = self.imports.get_mut(&constructor.name) {
179
179
-
import.used_as_type = true;
180
180
-
}
181
181
-
}
182
182
-
183
183
-
TypeAst::Constructor(constructor)
184
184
-
}
185
185
-
}
186
186
-
187
187
-
impl PatternFolder for Fixer {
188
188
-
fn fold_pattern_constructor(
189
189
-
&mut self,
190
190
-
location: SrcSpan,
191
191
-
name: EcoString,
192
192
-
arguments: Vec<CallArg<UntypedPattern>>,
193
193
-
module: Option<EcoString>,
194
194
-
with_spread: bool,
195
195
-
) -> UntypedPattern {
196
196
-
if module.is_none() && !self.local_types.contains(&name) {
197
197
-
if let Some(import) = self.imports.get_mut(&name) {
198
198
-
import.used_as_value = true;
199
199
-
}
200
200
-
}
201
201
-
202
202
-
Pattern::Constructor {
203
203
-
location,
204
204
-
name,
205
205
-
arguments,
206
206
-
module,
207
207
-
with_spread,
208
208
-
constructor: Inferred::Unknown,
209
209
-
type_: (),
210
210
-
}
211
211
-
}
212
212
-
}
213
213
-
214
214
-
#[derive(Debug, Default)]
215
215
-
struct Imported {
216
216
-
module: EcoString,
217
217
-
used_as_type: bool,
218
218
-
used_as_value: bool,
219
219
-
}
···
1
1
-
use super::*;
2
2
-
3
3
-
use camino::Utf8Path;
4
4
-
5
5
-
fn fix(src: &str) -> String {
6
6
-
parse_fix_and_format(&src.into(), Utf8Path::new("test")).unwrap()
7
7
-
}
8
8
-
9
9
-
#[test]
10
10
-
fn empty() {
11
11
-
assert_eq!(fix(""), "\n")
12
12
-
}
13
13
-
14
14
-
#[test]
15
15
-
fn import() {
16
16
-
assert_eq!(
17
17
-
fix("import gleam.{BitString}
18
18
-
19
19
-
type X =
20
20
-
BitString"),
21
21
-
"import gleam.{type BitArray}
22
22
-
23
23
-
type X =
24
24
-
BitArray
25
25
-
"
26
26
-
);
27
27
-
}
28
28
-
29
29
-
#[test]
30
30
-
fn import_new_syntax() {
31
31
-
assert_eq!(
32
32
-
fix("import gleam.{type BitString}
33
33
-
34
34
-
type X =
35
35
-
BitString"),
36
36
-
"import gleam.{type BitArray}
37
37
-
38
38
-
type X =
39
39
-
BitArray
40
40
-
"
41
41
-
);
42
42
-
}
43
43
-
44
44
-
#[test]
45
45
-
fn import_aliased() {
46
46
-
assert_eq!(
47
47
-
fix("import gleam.{type BitString as B}"),
48
48
-
"import gleam.{type BitArray as B}\n"
49
49
-
);
50
50
-
}
51
51
-
52
52
-
#[test]
53
53
-
fn alias() {
54
54
-
assert_eq!(
55
55
-
fix("pub type X =
56
56
-
BitString
57
57
-
"),
58
58
-
"pub type X =
59
59
-
BitArray
60
60
-
"
61
61
-
);
62
62
-
}
63
63
-
64
64
-
#[test]
65
65
-
fn alias_qualified() {
66
66
-
assert_eq!(
67
67
-
fix("import gleam
68
68
-
69
69
-
pub type X =
70
70
-
gleam.BitString
71
71
-
"),
72
72
-
"import gleam
73
73
-
74
74
-
pub type X =
75
75
-
gleam.BitArray
76
76
-
"
77
77
-
);
78
78
-
}
79
79
-
80
80
-
#[test]
81
81
-
fn alias_qualified_aliased() {
82
82
-
assert_eq!(
83
83
-
fix("import gleam as g
84
84
-
85
85
-
pub type X =
86
86
-
g.BitString
87
87
-
"),
88
88
-
"import gleam as g
89
89
-
90
90
-
pub type X =
91
91
-
g.BitArray
92
92
-
"
93
93
-
);
94
94
-
}
95
95
-
96
96
-
#[test]
97
97
-
fn custom_type() {
98
98
-
assert_eq!(
99
99
-
fix("pub type X {
100
100
-
X(BitString)
101
101
-
}
102
102
-
"),
103
103
-
"pub type X {
104
104
-
X(BitArray)
105
105
-
}
106
106
-
"
107
107
-
);
108
108
-
}
109
109
-
110
110
-
#[test]
111
111
-
fn custom_type_qualified() {
112
112
-
assert_eq!(
113
113
-
fix("import gleam
114
114
-
115
115
-
pub type X {
116
116
-
X(gleam.BitString)
117
117
-
}
118
118
-
"),
119
119
-
"import gleam
120
120
-
121
121
-
pub type X {
122
122
-
X(gleam.BitArray)
123
123
-
}
124
124
-
"
125
125
-
);
126
126
-
}
127
127
-
128
128
-
#[test]
129
129
-
fn custom_type_qualified_aliased() {
130
130
-
assert_eq!(
131
131
-
fix("import gleam as g
132
132
-
133
133
-
pub type X {
134
134
-
X(g.BitString)
135
135
-
}
136
136
-
"),
137
137
-
"import gleam as g
138
138
-
139
139
-
pub type X {
140
140
-
X(g.BitArray)
141
141
-
}
142
142
-
"
143
143
-
);
144
144
-
}
145
145
-
146
146
-
#[test]
147
147
-
fn shadowed_by_alias() {
148
148
-
assert_eq!(
149
149
-
fix("pub type X =
150
150
-
BitString
151
151
-
152
152
-
pub type BitString =
153
153
-
Int
154
154
-
"),
155
155
-
"pub type X =
156
156
-
BitString
157
157
-
158
158
-
pub type BitString =
159
159
-
Int
160
160
-
"
161
161
-
);
162
162
-
}
163
163
-
164
164
-
#[test]
165
165
-
fn shadowed_by_custom_type() {
166
166
-
assert_eq!(
167
167
-
fix("pub type X =
168
168
-
BitString
169
169
-
170
170
-
pub type BitString {
171
171
-
B
172
172
-
}
173
173
-
"),
174
174
-
"pub type X =
175
175
-
BitString
176
176
-
177
177
-
pub type BitString {
178
178
-
B
179
179
-
}
180
180
-
"
181
181
-
);
182
182
-
}
183
183
-
184
184
-
#[test]
185
185
-
fn shadowed_by_import() {
186
186
-
assert_eq!(
187
187
-
fix("import x.{BitString}
188
188
-
189
189
-
pub type X =
190
190
-
BitString
191
191
-
"),
192
192
-
"import x.{type BitString}
193
193
-
194
194
-
pub type X =
195
195
-
BitString
196
196
-
"
197
197
-
);
198
198
-
}
199
199
-
200
200
-
#[test]
201
201
-
fn return_type() {
202
202
-
assert_eq!(
203
203
-
fix("pub fn main() -> BitString {
204
204
-
todo
205
205
-
}
206
206
-
"),
207
207
-
"pub fn main() -> BitArray {
208
208
-
todo
209
209
-
}
210
210
-
"
211
211
-
);
212
212
-
}
213
213
-
214
214
-
#[test]
215
215
-
fn arguments() {
216
216
-
assert_eq!(
217
217
-
fix("pub fn main(
218
218
-
a: BitString,
219
219
-
b b: List(BitString),
220
220
-
z,
221
221
-
_: BitString,
222
222
-
_: BitString,
223
223
-
) -> Nil {
224
224
-
todo
225
225
-
}
226
226
-
"),
227
227
-
"pub fn main(
228
228
-
a: BitArray,
229
229
-
b b: List(BitArray),
230
230
-
z,
231
231
-
_: BitArray,
232
232
-
_: BitArray,
233
233
-
) -> Nil {
234
234
-
todo
235
235
-
}
236
236
-
"
237
237
-
);
238
238
-
}
239
239
-
240
240
-
#[test]
241
241
-
fn let_annotation() {
242
242
-
assert_eq!(
243
243
-
fix("pub fn main() {
244
244
-
let x: List(BitString) = todo
245
245
-
}
246
246
-
"),
247
247
-
"pub fn main() {
248
248
-
let x: List(BitArray) = todo
249
249
-
}
250
250
-
"
251
251
-
);
252
252
-
}
253
253
-
254
254
-
#[test]
255
255
-
fn use_annotation() {
256
256
-
assert_eq!(
257
257
-
fix("pub fn main() {
258
258
-
use x: List(BitString), y: BitString <- todo
259
259
-
}
260
260
-
"),
261
261
-
"pub fn main() {
262
262
-
use x: List(BitArray), y: BitArray <- todo
263
263
-
}
264
264
-
"
265
265
-
);
266
266
-
}
267
267
-
268
268
-
#[test]
269
269
-
fn constant() {
270
270
-
assert_eq!(
271
271
-
fix("pub const x: BitString = <<>>"),
272
272
-
"pub const x: BitArray = <<>>\n"
273
273
-
);
274
274
-
}
275
275
-
276
276
-
#[test]
277
277
-
fn imported_used_in_const() {
278
278
-
assert_eq!(
279
279
-
fix("import x.{X}
280
280
-
281
281
-
const x = X
282
282
-
"),
283
283
-
"import x.{X}
284
284
-
285
285
-
const x = X
286
286
-
"
287
287
-
);
288
288
-
}
289
289
-
290
290
-
#[test]
291
291
-
fn imported_type_only() {
292
292
-
assert_eq!(
293
293
-
fix("import x.{X}
294
294
-
295
295
-
const x = X
296
296
-
297
297
-
type Y {
298
298
-
X(X)
299
299
-
}
300
300
-
"),
301
301
-
"import x.{type X}
302
302
-
303
303
-
const x = X
304
304
-
305
305
-
type Y {
306
306
-
X(X)
307
307
-
}
308
308
-
"
309
309
-
);
310
310
-
}
311
311
-
312
312
-
#[test]
313
313
-
fn imported_value_and_type() {
314
314
-
assert_eq!(
315
315
-
fix("import x.{X}
316
316
-
317
317
-
const x = X
318
318
-
319
319
-
type Y {
320
320
-
Y(X)
321
321
-
}
322
322
-
"),
323
323
-
"import x.{type X, X}
324
324
-
325
325
-
const x = X
326
326
-
327
327
-
type Y {
328
328
-
Y(X)
329
329
-
}
330
330
-
"
331
331
-
);
332
332
-
}
333
333
-
334
334
-
#[test]
335
335
-
fn imported_value_only() {
336
336
-
assert_eq!(
337
337
-
fix("import x.{X}
338
338
-
339
339
-
const x = X
340
340
-
341
341
-
type X {
342
342
-
Z(X)
343
343
-
}
344
344
-
"),
345
345
-
"import x.{X}
346
346
-
347
347
-
const x = X
348
348
-
349
349
-
type X {
350
350
-
Z(X)
351
351
-
}
352
352
-
"
353
353
-
);
354
354
-
}
355
355
-
356
356
-
#[test]
357
357
-
fn pattern() {
358
358
-
assert_eq!(
359
359
-
fix("import x.{X}
360
360
-
361
361
-
pub fn main(x) {
362
362
-
case x {
363
363
-
X -> 1
364
364
-
_ -> 0
365
365
-
}
366
366
-
}
367
367
-
"),
368
368
-
"import x.{X}
369
369
-
370
370
-
pub fn main(x) {
371
371
-
case x {
372
372
-
X -> 1
373
373
-
_ -> 0
374
374
-
}
375
375
-
}
376
376
-
"
377
377
-
);
378
378
-
}
379
379
-
380
380
-
#[test]
381
381
-
fn aliased_type_import() {
382
382
-
assert_eq!(
383
383
-
fix("import x.{X as Y}
384
384
-
385
385
-
pub type Z =
386
386
-
Y
387
387
-
"),
388
388
-
"import x.{type X as Y}
389
389
-
390
390
-
pub type Z =
391
391
-
Y
392
392
-
"
393
393
-
);
394
394
-
}
395
395
-
396
396
-
#[test]
397
397
-
fn already_fixed() {
398
398
-
assert_eq!(
399
399
-
fix("import x.{type X, X}
400
400
-
401
401
-
pub const x = X
402
402
-
403
403
-
pub type Z =
404
404
-
X
405
405
-
"),
406
406
-
"import x.{type X, X}
407
407
-
408
408
-
pub const x = X
409
409
-
410
410
-
pub type Z =
411
411
-
X
412
412
-
",
413
413
-
);
414
414
-
}
415
415
-
416
416
-
#[test]
417
417
-
fn error_type() {
418
418
-
assert_eq!(
419
419
-
fix("import thing.{Error}
420
420
-
421
421
-
pub fn main() -> Result(Nil, Error) {
422
422
-
Error(thing.make_error())
423
423
-
}
424
424
-
"),
425
425
-
"import thing.{type Error}
426
426
-
427
427
-
pub fn main() -> Result(Nil, Error) {
428
428
-
Error(thing.make_error())
429
429
-
}
430
430
-
"
431
431
-
);
432
432
-
}
433
433
-
434
434
-
#[test]
435
435
-
fn ok_type() {
436
436
-
assert_eq!(
437
437
-
fix("import thing.{Ok}
438
438
-
439
439
-
pub fn main() -> Result(Ok, Nil) {
440
440
-
Ok(thing.make_ok())
441
441
-
}
442
442
-
"),
443
443
-
"import thing.{type Ok}
444
444
-
445
445
-
pub fn main() -> Result(Ok, Nil) {
446
446
-
Ok(thing.make_ok())
447
447
-
}
448
448
-
"
449
449
-
);
450
450
-
}
451
451
-
452
452
-
#[test]
453
453
-
fn list_value() {
454
454
-
assert_eq!(
455
455
-
fix("import thing.{List}
456
456
-
457
457
-
pub fn main() -> List(Int) {
458
458
-
List
459
459
-
[]
460
460
-
}
461
461
-
"),
462
462
-
"import thing.{List}
463
463
-
464
464
-
pub fn main() -> List(Int) {
465
465
-
List
466
466
-
[]
467
467
-
}
468
468
-
"
469
469
-
);
470
470
-
}
471
471
-
#[test]
472
472
-
fn result_value() {
473
473
-
assert_eq!(
474
474
-
fix("import thing.{Result}
475
475
-
476
476
-
pub fn main() -> Result(Int, Nil) {
477
477
-
Result
478
478
-
Ok(1)
479
479
-
}
480
480
-
"),
481
481
-
"import thing.{Result}
482
482
-
483
483
-
pub fn main() -> Result(Int, Nil) {
484
484
-
Result
485
485
-
Ok(1)
486
486
-
}
487
487
-
"
488
488
-
);
489
489
-
}
490
490
-
491
491
-
#[test]
492
492
-
fn const_error_type() {
493
493
-
assert_eq!(
494
494
-
fix("import thing.{Error}
495
495
-
496
496
-
pub const x = Error
497
497
-
498
498
-
pub type Y =
499
499
-
Error
500
500
-
"),
501
501
-
"import thing.{type Error}
502
502
-
503
503
-
pub const x = Error
504
504
-
505
505
-
pub type Y =
506
506
-
Error
507
507
-
"
508
508
-
);
509
509
-
}
510
510
-
511
511
-
#[test]
512
512
-
fn const_ok_type() {
513
513
-
assert_eq!(
514
514
-
fix("import thing.{Ok}
515
515
-
516
516
-
pub const x = Ok
517
517
-
518
518
-
pub type Y =
519
519
-
Ok
520
520
-
"),
521
521
-
"import thing.{type Ok}
522
522
-
523
523
-
pub const x = Ok
524
524
-
525
525
-
pub type Y =
526
526
-
Ok
527
527
-
"
528
528
-
);
529
529
-
}
530
530
-
531
531
-
#[test]
532
532
-
fn const_list_value() {
533
533
-
assert_eq!(
534
534
-
fix("import thing.{List}
535
535
-
536
536
-
pub const x = List
537
537
-
538
538
-
pub type Y =
539
539
-
List(Int)
540
540
-
"),
541
541
-
"import thing.{List}
542
542
-
543
543
-
pub const x = List
544
544
-
545
545
-
pub type Y =
546
546
-
List(Int)
547
547
-
"
548
548
-
);
549
549
-
}
550
550
-
551
551
-
#[test]
552
552
-
fn const_result_value() {
553
553
-
assert_eq!(
554
554
-
fix("import thing.{Result}
555
555
-
556
556
-
pub const x = Result
557
557
-
558
558
-
pub type Y =
559
559
-
Result(Int, Nil)
560
560
-
"),
561
561
-
"import thing.{Result}
562
562
-
563
563
-
pub const x = Result
564
564
-
565
565
-
pub type Y =
566
566
-
Result(Int, Nil)
567
567
-
"
568
568
-
);
569
569
-
}