Skip to content

Commit e51319c

Browse files
committed
Add tests for all possible cases for this feature.
1 parent 0c30c19 commit e51319c

13 files changed

+574
-0
lines changed

compiler-core/src/type_/tests/errors.rs

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,3 +3308,223 @@ pub fn main() {
33083308
"
33093309
);
33103310
}
3311+
3312+
#[test]
3313+
fn unknown_variable_possible_modules_1() {
3314+
assert_module_error!(
3315+
("module", "pub const one = 1"),
3316+
"
3317+
import module
3318+
pub fn main() {
3319+
one
3320+
}
3321+
"
3322+
);
3323+
}
3324+
3325+
#[test]
3326+
fn unknown_variable_possible_modules_2() {
3327+
assert_module_error!(
3328+
("module", "pub fn add(x: Int, y: Int) { x + y }"),
3329+
"
3330+
import module
3331+
pub fn main() {
3332+
add(1, 1)
3333+
}
3334+
"
3335+
);
3336+
}
3337+
3338+
#[test]
3339+
fn unknown_variable_possible_modules_3() {
3340+
assert_module_error!(
3341+
("module", "pub fn add(x: Int) { x + 1 }"),
3342+
"
3343+
import module
3344+
pub fn main() {
3345+
add(1, 1)
3346+
}
3347+
"
3348+
);
3349+
}
3350+
3351+
#[test]
3352+
fn unknown_variable_possible_modules_4() {
3353+
assert_module_error!(
3354+
("module", "pub fn add(x: Float, y: Float) { x +. y }"),
3355+
"
3356+
import module
3357+
pub fn main() {
3358+
add(1, 1)
3359+
}
3360+
"
3361+
);
3362+
}
3363+
3364+
#[test]
3365+
fn unknown_variable_possible_modules_5() {
3366+
assert_module_error!(
3367+
(
3368+
"module",
3369+
"
3370+
fn add(x: Int, y: Int) { x + y }
3371+
"
3372+
),
3373+
"
3374+
import module
3375+
pub fn main() {
3376+
add(1, 1)
3377+
}
3378+
"
3379+
);
3380+
}
3381+
3382+
#[test]
3383+
fn unknown_variable_possible_modules_6() {
3384+
assert_module_error!(
3385+
(
3386+
"module",
3387+
"
3388+
pub const add = internal_add
3389+
fn internal_add(x: Int, y: Int) { x + y }
3390+
"
3391+
),
3392+
"
3393+
import module
3394+
pub fn main() {
3395+
add(1, 1)
3396+
}
3397+
"
3398+
);
3399+
}
3400+
3401+
#[test]
3402+
fn unknown_variable_possible_modules_7() {
3403+
assert_module_error!(
3404+
(
3405+
"module",
3406+
"
3407+
pub type OneOrTwo {
3408+
One
3409+
Two
3410+
}
3411+
"
3412+
),
3413+
"
3414+
import module
3415+
pub fn main() {
3416+
One
3417+
}
3418+
"
3419+
);
3420+
}
3421+
3422+
#[test]
3423+
fn unknown_variable_possible_modules_8() {
3424+
assert_module_error!(
3425+
(
3426+
"moduleone",
3427+
"
3428+
pub type MyType {
3429+
MyRecord(x: Int, y: Int)
3430+
}
3431+
"
3432+
),
3433+
(
3434+
"moduletwo",
3435+
"
3436+
pub type AnotherType {
3437+
MyRecord(x: Int)
3438+
}
3439+
"
3440+
),
3441+
"
3442+
import moduleone
3443+
import moduletwo
3444+
pub fn main() {
3445+
MyRecord(1)
3446+
}
3447+
"
3448+
);
3449+
}
3450+
3451+
#[test]
3452+
fn unknown_variable_possible_modules_9() {
3453+
assert_module_error!(
3454+
(
3455+
"module",
3456+
"
3457+
pub fn add(x: Int) {
3458+
x + 1
3459+
}
3460+
"
3461+
),
3462+
"
3463+
import module
3464+
pub fn main() {
3465+
1 |> add
3466+
}
3467+
"
3468+
);
3469+
}
3470+
3471+
#[test]
3472+
fn unknown_variable_possible_modules_10() {
3473+
assert_module_error!(
3474+
(
3475+
"module",
3476+
"
3477+
pub fn add(x: Int, y: Int) {
3478+
x + y
3479+
}
3480+
"
3481+
),
3482+
"
3483+
import module
3484+
pub fn main() {
3485+
1 |> add(2)
3486+
}
3487+
"
3488+
);
3489+
}
3490+
3491+
#[test]
3492+
fn unknown_variable_possible_modules_11() {
3493+
assert_module_error!(
3494+
(
3495+
"module",
3496+
"
3497+
pub fn add(x: Int) {
3498+
fn(y: Int) { x + y }
3499+
}
3500+
"
3501+
),
3502+
"
3503+
import module
3504+
pub fn main() {
3505+
1 |> add(2)
3506+
}
3507+
"
3508+
);
3509+
}
3510+
3511+
#[test]
3512+
fn unknown_variable_possible_modules_12() {
3513+
assert_module_error!(
3514+
(
3515+
"module",
3516+
"
3517+
pub fn wibble(_) {
3518+
1
3519+
}
3520+
"
3521+
),
3522+
"
3523+
import module
3524+
pub fn main() {
3525+
use <- wibble
3526+
1
3527+
}
3528+
"
3529+
);
3530+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nimport module\npub fn main() {\n one\n}\n"
4+
---
5+
----- SOURCE CODE
6+
-- module.gleam
7+
pub const one = 1
8+
9+
-- main.gleam
10+
11+
import module
12+
pub fn main() {
13+
one
14+
}
15+
16+
17+
----- ERROR
18+
error: Unknown variable
19+
┌─ /src/one/two.gleam:4:5
20+
21+
4one
22+
^^^
23+
24+
The name `one` is not in scope here.
25+
Did you mean one of these:
26+
27+
- module.one
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nimport module\npub fn main() {\n 1 |> add(2)\n}\n"
4+
---
5+
----- SOURCE CODE
6+
-- module.gleam
7+
8+
pub fn add(x: Int, y: Int) {
9+
x + y
10+
}
11+
12+
13+
-- main.gleam
14+
15+
import module
16+
pub fn main() {
17+
1 |> add(2)
18+
}
19+
20+
21+
----- ERROR
22+
error: Unknown variable
23+
┌─ /src/one/two.gleam:4:10
24+
25+
41 |> add(2)
26+
^^^
27+
28+
The name `add` is not in scope here.
29+
Did you mean one of these:
30+
31+
- module.add
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nimport module\npub fn main() {\n 1 |> add(2)\n}\n"
4+
---
5+
----- SOURCE CODE
6+
-- module.gleam
7+
8+
pub fn add(x: Int) {
9+
fn(y: Int) { x + y }
10+
}
11+
12+
13+
-- main.gleam
14+
15+
import module
16+
pub fn main() {
17+
1 |> add(2)
18+
}
19+
20+
21+
----- ERROR
22+
error: Unknown variable
23+
┌─ /src/one/two.gleam:4:10
24+
25+
41 |> add(2)
26+
^^^
27+
28+
The name `add` is not in scope here.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nimport module\npub fn main() {\n use <- wibble\n 1\n}\n"
4+
---
5+
----- SOURCE CODE
6+
-- module.gleam
7+
8+
pub fn wibble(_) {
9+
1
10+
}
11+
12+
13+
-- main.gleam
14+
15+
import module
16+
pub fn main() {
17+
use <- wibble
18+
1
19+
}
20+
21+
22+
----- ERROR
23+
error: Unknown variable
24+
┌─ /src/one/two.gleam:4:12
25+
26+
4use <- wibble
27+
^^^^^^
28+
29+
The name `wibble` is not in scope here.
30+
Did you mean one of these:
31+
32+
- module.wibble
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nimport module\npub fn main() {\n add(1, 1)\n}\n"
4+
---
5+
----- SOURCE CODE
6+
-- module.gleam
7+
pub fn add(x: Int, y: Int) { x + y }
8+
9+
-- main.gleam
10+
11+
import module
12+
pub fn main() {
13+
add(1, 1)
14+
}
15+
16+
17+
----- ERROR
18+
error: Unknown variable
19+
┌─ /src/one/two.gleam:4:5
20+
21+
4add(1, 1)
22+
^^^
23+
24+
The name `add` is not in scope here.
25+
Did you mean one of these:
26+
27+
- module.add
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nimport module\npub fn main() {\n add(1, 1)\n}\n"
4+
---
5+
----- SOURCE CODE
6+
-- module.gleam
7+
pub fn add(x: Int) { x + 1 }
8+
9+
-- main.gleam
10+
11+
import module
12+
pub fn main() {
13+
add(1, 1)
14+
}
15+
16+
17+
----- ERROR
18+
error: Unknown variable
19+
┌─ /src/one/two.gleam:4:5
20+
21+
4add(1, 1)
22+
^^^
23+
24+
The name `add` is not in scope here.

0 commit comments

Comments
 (0)