Skip to content

Commit 3e2fc4d

Browse files
committed
Add tests for all possible cases for this feature.
1 parent fe00ec7 commit 3e2fc4d

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
@@ -3294,3 +3294,223 @@ opaque type Wibble {
32943294
"
32953295
);
32963296
}
3297+
3298+
#[test]
3299+
fn unknown_variable_possible_modules_1() {
3300+
assert_module_error!(
3301+
("module", "pub const one = 1"),
3302+
"
3303+
import module
3304+
pub fn main() {
3305+
one
3306+
}
3307+
"
3308+
);
3309+
}
3310+
3311+
#[test]
3312+
fn unknown_variable_possible_modules_2() {
3313+
assert_module_error!(
3314+
("module", "pub fn add(x: Int, y: Int) { x + y }"),
3315+
"
3316+
import module
3317+
pub fn main() {
3318+
add(1, 1)
3319+
}
3320+
"
3321+
);
3322+
}
3323+
3324+
#[test]
3325+
fn unknown_variable_possible_modules_3() {
3326+
assert_module_error!(
3327+
("module", "pub fn add(x: Int) { x + 1 }"),
3328+
"
3329+
import module
3330+
pub fn main() {
3331+
add(1, 1)
3332+
}
3333+
"
3334+
);
3335+
}
3336+
3337+
#[test]
3338+
fn unknown_variable_possible_modules_4() {
3339+
assert_module_error!(
3340+
("module", "pub fn add(x: Float, y: Float) { x +. y }"),
3341+
"
3342+
import module
3343+
pub fn main() {
3344+
add(1, 1)
3345+
}
3346+
"
3347+
);
3348+
}
3349+
3350+
#[test]
3351+
fn unknown_variable_possible_modules_5() {
3352+
assert_module_error!(
3353+
(
3354+
"module",
3355+
"
3356+
fn add(x: Int, y: Int) { x + y }
3357+
"
3358+
),
3359+
"
3360+
import module
3361+
pub fn main() {
3362+
add(1, 1)
3363+
}
3364+
"
3365+
);
3366+
}
3367+
3368+
#[test]
3369+
fn unknown_variable_possible_modules_6() {
3370+
assert_module_error!(
3371+
(
3372+
"module",
3373+
"
3374+
pub const add = internal_add
3375+
fn internal_add(x: Int, y: Int) { x + y }
3376+
"
3377+
),
3378+
"
3379+
import module
3380+
pub fn main() {
3381+
add(1, 1)
3382+
}
3383+
"
3384+
);
3385+
}
3386+
3387+
#[test]
3388+
fn unknown_variable_possible_modules_7() {
3389+
assert_module_error!(
3390+
(
3391+
"module",
3392+
"
3393+
pub type OneOrTwo {
3394+
One
3395+
Two
3396+
}
3397+
"
3398+
),
3399+
"
3400+
import module
3401+
pub fn main() {
3402+
One
3403+
}
3404+
"
3405+
);
3406+
}
3407+
3408+
#[test]
3409+
fn unknown_variable_possible_modules_8() {
3410+
assert_module_error!(
3411+
(
3412+
"moduleone",
3413+
"
3414+
pub type MyType {
3415+
MyRecord(x: Int, y: Int)
3416+
}
3417+
"
3418+
),
3419+
(
3420+
"moduletwo",
3421+
"
3422+
pub type AnotherType {
3423+
MyRecord(x: Int)
3424+
}
3425+
"
3426+
),
3427+
"
3428+
import moduleone
3429+
import moduletwo
3430+
pub fn main() {
3431+
MyRecord(1)
3432+
}
3433+
"
3434+
);
3435+
}
3436+
3437+
#[test]
3438+
fn unknown_variable_possible_modules_9() {
3439+
assert_module_error!(
3440+
(
3441+
"module",
3442+
"
3443+
pub fn add(x: Int) {
3444+
x + 1
3445+
}
3446+
"
3447+
),
3448+
"
3449+
import module
3450+
pub fn main() {
3451+
1 |> add
3452+
}
3453+
"
3454+
);
3455+
}
3456+
3457+
#[test]
3458+
fn unknown_variable_possible_modules_10() {
3459+
assert_module_error!(
3460+
(
3461+
"module",
3462+
"
3463+
pub fn add(x: Int, y: Int) {
3464+
x + y
3465+
}
3466+
"
3467+
),
3468+
"
3469+
import module
3470+
pub fn main() {
3471+
1 |> add(2)
3472+
}
3473+
"
3474+
);
3475+
}
3476+
3477+
#[test]
3478+
fn unknown_variable_possible_modules_11() {
3479+
assert_module_error!(
3480+
(
3481+
"module",
3482+
"
3483+
pub fn add(x: Int) {
3484+
fn(y: Int) { x + y }
3485+
}
3486+
"
3487+
),
3488+
"
3489+
import module
3490+
pub fn main() {
3491+
1 |> add(2)
3492+
}
3493+
"
3494+
);
3495+
}
3496+
3497+
#[test]
3498+
fn unknown_variable_possible_modules_12() {
3499+
assert_module_error!(
3500+
(
3501+
"module",
3502+
"
3503+
pub fn wibble(_) {
3504+
1
3505+
}
3506+
"
3507+
),
3508+
"
3509+
import module
3510+
pub fn main() {
3511+
use <- wibble
3512+
1
3513+
}
3514+
"
3515+
);
3516+
}
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)