Skip to content

Commit 5e2ff63

Browse files
authored
Rollup merge of rust-lang#55919 - Turbo87:num-tests, r=dtolnay
core/tests/num: Simplify `test_int_from_str_overflow()` test code This commit changes the test code to compare against easier-to-read, static values instead of relying on the result of `wrapping_add()` which may or may not result in the value that we expect.
2 parents c87c31b + cfbae3e commit 5e2ff63

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/libcore/tests/num/mod.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,28 @@ fn from_str_issue7588() {
8282

8383
#[test]
8484
fn test_int_from_str_overflow() {
85-
let mut i8_val: i8 = 127;
86-
assert_eq!("127".parse::<i8>().ok(), Some(i8_val));
85+
assert_eq!("127".parse::<i8>().ok(), Some(127i8));
8786
assert_eq!("128".parse::<i8>().ok(), None);
8887

89-
i8_val = i8_val.wrapping_add(1);
90-
assert_eq!("-128".parse::<i8>().ok(), Some(i8_val));
88+
assert_eq!("-128".parse::<i8>().ok(), Some(-128i8));
9189
assert_eq!("-129".parse::<i8>().ok(), None);
9290

93-
let mut i16_val: i16 = 32_767;
94-
assert_eq!("32767".parse::<i16>().ok(), Some(i16_val));
91+
assert_eq!("32767".parse::<i16>().ok(), Some(32_767i16));
9592
assert_eq!("32768".parse::<i16>().ok(), None);
9693

97-
i16_val = i16_val.wrapping_add(1);
98-
assert_eq!("-32768".parse::<i16>().ok(), Some(i16_val));
94+
assert_eq!("-32768".parse::<i16>().ok(), Some(-32_768i16));
9995
assert_eq!("-32769".parse::<i16>().ok(), None);
10096

101-
let mut i32_val: i32 = 2_147_483_647;
102-
assert_eq!("2147483647".parse::<i32>().ok(), Some(i32_val));
97+
assert_eq!("2147483647".parse::<i32>().ok(), Some(2_147_483_647i32));
10398
assert_eq!("2147483648".parse::<i32>().ok(), None);
10499

105-
i32_val = i32_val.wrapping_add(1);
106-
assert_eq!("-2147483648".parse::<i32>().ok(), Some(i32_val));
100+
assert_eq!("-2147483648".parse::<i32>().ok(), Some(-2_147_483_648i32));
107101
assert_eq!("-2147483649".parse::<i32>().ok(), None);
108102

109-
let mut i64_val: i64 = 9_223_372_036_854_775_807;
110-
assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(i64_val));
103+
assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(9_223_372_036_854_775_807i64));
111104
assert_eq!("9223372036854775808".parse::<i64>().ok(), None);
112105

113-
i64_val = i64_val.wrapping_add(1);
114-
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val));
106+
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(-9_223_372_036_854_775_808i64));
115107
assert_eq!("-9223372036854775809".parse::<i64>().ok(), None);
116108
}
117109

0 commit comments

Comments
 (0)