Skip to content

Commit 30e2ad2

Browse files
added tests for negative cases, minor changes
1 parent d2edf78 commit 30e2ad2

8 files changed

+81
-4
lines changed

compiler-core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ The error from the encryption library was:
14431443
title: "Float is outside Erlang's floating point range".into(),
14441444
text: wrap("This float value is too large to be represented by \
14451445
Erlang's floating point type. To avoid this error float values must be in the range \
1446-
-1.7976931348623157e308f64 - 1.7976931348623157e308f64."),
1446+
-1.7976931348623157e308 - 1.7976931348623157e308."),
14471447
hint: None,
14481448
level: Level::Error,
14491449
location: Some(Location {

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

+15
Original file line numberDiff line numberDiff line change
@@ -2670,3 +2670,18 @@ fn out_of_range_erlang_float_in_pattern() {
26702670
fn out_of_range_erlang_float_in_const() {
26712671
assert_module_error!(r#"const x = 1.8e308"#);
26722672
}
2673+
2674+
#[test]
2675+
fn negative_out_of_range_erlang_float() {
2676+
assert_error!(r#"-1.8e308"#);
2677+
}
2678+
2679+
#[test]
2680+
fn negative_out_of_range_erlang_float_in_pattern() {
2681+
assert_error!(r#"let assert [-1.8e308, b] = [x, y]"#);
2682+
}
2683+
2684+
#[test]
2685+
fn negative_out_of_range_erlang_float_in_const() {
2686+
assert_module_error!(r#"const x = -1.8e308"#);
2687+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "-1.8e308"
4+
snapshot_kind: text
5+
---
6+
----- SOURCE CODE
7+
-1.8e308
8+
9+
----- ERROR
10+
error: Float is outside Erlang's floating point range
11+
┌─ /src/one/two.gleam:1:1
12+
13+
1-1.8e308
14+
^^^^^^^^
15+
16+
This float value is too large to be represented by Erlang's floating point
17+
type. To avoid this error float values must be in the range
18+
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: const x = -1.8e308
4+
snapshot_kind: text
5+
---
6+
----- SOURCE CODE
7+
const x = -1.8e308
8+
9+
----- ERROR
10+
error: Float is outside Erlang's floating point range
11+
┌─ /src/one/two.gleam:1:11
12+
13+
1const x = -1.8e308
14+
^^^^^^^^
15+
16+
This float value is too large to be represented by Erlang's floating point
17+
type. To avoid this error float values must be in the range
18+
-1.7976931348623157e308 - 1.7976931348623157e308.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "let assert [-1.8e308, b] = [x, y]"
4+
snapshot_kind: text
5+
---
6+
----- SOURCE CODE
7+
let assert [-1.8e308, b] = [x, y]
8+
9+
----- ERROR
10+
error: Unknown variable
11+
┌─ /src/one/two.gleam:1:29
12+
13+
1let assert [-1.8e308, b] = [x, y]
14+
^
15+
16+
The name `x` is not in scope here.
17+
18+
error: Float is outside Erlang's floating point range
19+
┌─ /src/one/two.gleam:1:13
20+
21+
1let assert [-1.8e308, b] = [x, y]
22+
^^^^^^^^
23+
24+
This float value is too large to be represented by Erlang's floating point
25+
type. To avoid this error float values must be in the range
26+
-1.7976931348623157e308 - 1.7976931348623157e308.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__out_of_range_erlang_float.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ error: Float is outside Erlang's floating point range
1515

1616
This float value is too large to be represented by Erlang's floating point
1717
type. To avoid this error float values must be in the range
18-
-1.7976931348623157e308f64 - 1.7976931348623157e308f64.
18+
-1.7976931348623157e308 - 1.7976931348623157e308.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__out_of_range_erlang_float_in_const.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ error: Float is outside Erlang's floating point range
1515

1616
This float value is too large to be represented by Erlang's floating point
1717
type. To avoid this error float values must be in the range
18-
-1.7976931348623157e308f64 - 1.7976931348623157e308f64.
18+
-1.7976931348623157e308 - 1.7976931348623157e308.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__out_of_range_erlang_float_in_pattern.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ error: Float is outside Erlang's floating point range
2323

2424
This float value is too large to be represented by Erlang's floating point
2525
type. To avoid this error float values must be in the range
26-
-1.7976931348623157e308f64 - 1.7976931348623157e308f64.
26+
-1.7976931348623157e308 - 1.7976931348623157e308.

0 commit comments

Comments
 (0)