1 #![cfg(feature = "std")]
2
3 use std::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize};
4
5 use num_format::{CustomFormat, Locale, WriteFormatted};
6
7 #[test]
test_no_bytes_written()8 fn test_no_bytes_written() {
9 macro_rules! test1 {
10 ( $( $n:expr ),* ) => {
11 {
12 $(
13 let mut s = String::new();
14 let c = s.write_formatted(&$n, &Locale::en).unwrap();
15 assert_eq!(c, 5);
16 )*
17 }
18 };
19 }
20
21 test1!(
22 1_000u16,
23 1_000u32,
24 1_000usize,
25 1_000u64,
26 1_000u128,
27 1_000i16,
28 1_000i32,
29 1_000isize,
30 1_000i64,
31 1_000i128,
32 NonZeroU16::new(1_000).unwrap(),
33 NonZeroU32::new(1_000).unwrap(),
34 NonZeroUsize::new(1_000).unwrap(),
35 NonZeroU64::new(1_000).unwrap(),
36 NonZeroU128::new(1_000).unwrap()
37 );
38
39 macro_rules! test2 {
40 ( $( $n:expr ),* ) => {
41 {
42 $(
43 let mut s = String::new();
44 let format = CustomFormat::builder().separator("").build().unwrap();
45 let c = s.write_formatted(&$n, &format).unwrap();
46 assert_eq!(c, 8);
47 )*
48 }
49 };
50 }
51
52 test2!(
53 1_000u16,
54 1_000u32,
55 1_000usize,
56 1_000u64,
57 1_000u128,
58 1_000i16,
59 1_000i32,
60 1_000isize,
61 1_000i64,
62 1_000i128,
63 NonZeroU16::new(1_000).unwrap(),
64 NonZeroU32::new(1_000).unwrap(),
65 NonZeroUsize::new(1_000).unwrap(),
66 NonZeroU64::new(1_000).unwrap(),
67 NonZeroU128::new(1_000).unwrap()
68 );
69 }
70