File: test_no_bytes_written.rs

package info (click to toggle)
rust-num-format 0.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 564 kB
  • sloc: makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#![cfg(feature = "std")]

use std::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize};

use num_format::{CustomFormat, Locale, WriteFormatted};

#[test]
fn test_no_bytes_written() {
    macro_rules! test1 {
        ( $( $n:expr ),* ) => {
            {
                $(
                    let mut s = String::new();
                    let c = s.write_formatted(&$n, &Locale::en).unwrap();
                    assert_eq!(c, 5);
                )*
            }
        };
    }

    test1!(
        1_000u16,
        1_000u32,
        1_000usize,
        1_000u64,
        1_000u128,
        1_000i16,
        1_000i32,
        1_000isize,
        1_000i64,
        1_000i128,
        NonZeroU16::new(1_000).unwrap(),
        NonZeroU32::new(1_000).unwrap(),
        NonZeroUsize::new(1_000).unwrap(),
        NonZeroU64::new(1_000).unwrap(),
        NonZeroU128::new(1_000).unwrap()
    );

    macro_rules! test2 {
        ( $( $n:expr ),* ) => {
            {
                $(
                    let mut s = String::new();
                    let format = CustomFormat::builder().separator("𠜱").build().unwrap();
                    let c = s.write_formatted(&$n, &format).unwrap();
                    assert_eq!(c, 8);
                )*
            }
        };
    }

    test2!(
        1_000u16,
        1_000u32,
        1_000usize,
        1_000u64,
        1_000u128,
        1_000i16,
        1_000i32,
        1_000isize,
        1_000i64,
        1_000i128,
        NonZeroU16::new(1_000).unwrap(),
        NonZeroU32::new(1_000).unwrap(),
        NonZeroUsize::new(1_000).unwrap(),
        NonZeroU64::new(1_000).unwrap(),
        NonZeroU128::new(1_000).unwrap()
    );
}