blob: 53558689daa6dec172eac6174006d2c7072670d0 [file] [log] [blame]
Haibo Huanga4c5ece2020-12-29 20:32:47 -08001#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless, string_lit_as_bytes))]
Yi Kong8884bbe2020-08-31 01:13:13 +08002#![allow(non_snake_case)]
3
4extern crate itoa;
5
6macro_rules! test {
7 (
8 $(
9 $(#[$attr:meta])*
10 $name:ident($value:expr, $expected:expr)
11 ),*
12 ) => {
13 $(
14 $(#[$attr])*
15 #[test]
16 fn $name() {
17 #[cfg(feature = "std")]
18 {
19 let mut buf = [b'\0'; 40];
20 let len = itoa::write(&mut buf[..], $value).unwrap();
21 assert_eq!(&buf[0..len], $expected.as_bytes());
22 }
23
24 let mut s = String::new();
25 itoa::fmt(&mut s, $value).unwrap();
26 assert_eq!(s, $expected);
27 }
28 )*
29 }
30}
31
Haibo Huanga4c5ece2020-12-29 20:32:47 -080032test! {
Yi Kong8884bbe2020-08-31 01:13:13 +080033 test_u64_0(0u64, "0"),
34 test_u64_half(<u32>::max_value() as u64, "4294967295"),
35 test_u64_max(<u64>::max_value(), "18446744073709551615"),
36 test_i64_min(<i64>::min_value(), "-9223372036854775808"),
37
38 test_i16_0(0i16, "0"),
39 test_i16_min(<i16>::min_value(), "-32768"),
40
41 #[cfg(feature = "i128")]
42 test_u128_0(0u128, "0"),
43 #[cfg(feature = "i128")]
44 test_u128_max(<u128>::max_value(), "340282366920938463463374607431768211455"),
45 #[cfg(feature = "i128")]
46 test_i128_min(<i128>::min_value(), "-170141183460469231731687303715884105728")
47}