Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 410ede9

Browse files
committed
Add some tests in number evaluvation and hover to prevent regression
Added a test near positive extermes and two test near negative extermes as well one for 0. Added a test using the `as` cast and one with comparison with 0.
1 parent b801792 commit 410ede9

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

crates/hir-ty/src/consteval/tests.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,57 @@ fn consts() {
20182018
"#,
20192019
6,
20202020
);
2021+
2022+
check_number(
2023+
r#"
2024+
const F1: i32 = 2147483647;
2025+
const F2: i32 = F1 - 25;
2026+
const GOAL: i32 = F2;
2027+
"#,
2028+
2147483622,
2029+
);
2030+
2031+
check_number(
2032+
r#"
2033+
const F1: i32 = -2147483648;
2034+
const F2: i32 = F1 + 18;
2035+
const GOAL: i32 = F2;
2036+
"#,
2037+
-2147483630,
2038+
);
2039+
2040+
check_number(
2041+
r#"
2042+
const F1: i32 = 10;
2043+
const F2: i32 = F1 - 20;
2044+
const GOAL: i32 = F2;
2045+
"#,
2046+
-10,
2047+
);
2048+
2049+
check_number(
2050+
r#"
2051+
const F1: i32 = 25;
2052+
const F2: i32 = F1 - 25;
2053+
const GOAL: i32 = F2;
2054+
"#,
2055+
0,
2056+
);
2057+
2058+
check_number(
2059+
r#"
2060+
const A: i32 = -2147483648;
2061+
const GOAL: bool = A > 0;
2062+
"#,
2063+
0,
2064+
);
2065+
2066+
check_number(
2067+
r#"
2068+
const GOAL: i64 = (-2147483648_i32) as i64;
2069+
"#,
2070+
-2147483648,
2071+
);
20212072
}
20222073

20232074
#[test]

crates/ide/src/hover/tests.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,39 @@ const foo$0: u32 = {
779779
```
780780
"#]],
781781
);
782+
783+
check(
784+
r#"const FOO$0: i32 = -2147483648;"#,
785+
expect![[r#"
786+
*FOO*
787+
788+
```rust
789+
test
790+
```
791+
792+
```rust
793+
const FOO: i32 = -2147483648 (0x80000000)
794+
```
795+
"#]],
796+
);
797+
798+
check(
799+
r#"
800+
const FOO: i32 = -2147483648;
801+
const BAR$0: bool = FOO > 0;
802+
"#,
803+
expect![[r#"
804+
*BAR*
805+
806+
```rust
807+
test
808+
```
809+
810+
```rust
811+
const BAR: bool = false
812+
```
813+
"#]],
814+
);
782815
}
783816

784817
#[test]

0 commit comments

Comments
 (0)