Debian Codegraph @

tests/test.rs

raw symbols SCIP
1 use humansizerust-analyzer cargo humansize 2.1.3 crate/::{
2 format_size, format_size_i, BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#, FixedAtrust-analyzer cargo humansize 2.1.3 options/FixedAt#, FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#, BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY., DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL., WINDOWSrust-analyzer cargo humansize 2.1.3 options/defaults/WINDOWS.,
3 };
4
5 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
6 fn test_sizesrust-analyzer cargo humansize 2.1.3 test_sizes().() {
7 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(0u32, BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.), "0 B");
8 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(999u32, BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.), "999 B");
9 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000u32, BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.), "1000 B");
10 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000u32, DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.), "1 kB");
11 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1023u32, BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.), "1023 B");
12 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1023u32, DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.), "1.02 kB");
13 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1024u32, BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.), "1 KiB");
14 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1024u32, WINDOWSrust-analyzer cargo humansize 2.1.3 options/defaults/WINDOWS.), "1 kB");
15
16 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size_i(1000f32, DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.), "1 kB");
17 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size_i(1000f64, DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.), "1 kB");
18
19
20 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.).space_after_valuerust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]space_after_value().(false);
21 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000u32, custom_options), "1kB");
22
23 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.).suffixrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]suffix().("/s");
24 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(999u32, custom_options), "999 B/s");
25
26 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.)
27 .suffixrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]suffix().("/day")
28 .space_after_valuerust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]space_after_value().(false);
29 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000u32, custom_options), "1kB/day");
30
31 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.).fixed_atrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]fixed_at().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FixedAtrust-analyzer cargo humansize 2.1.3 options/FixedAt#::Baserust-analyzer cargo humansize 2.1.3 options/FixedAt#Base#));
32 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(2048u32, custom_options), "2048 B");
33
34 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.)
35 .fixed_atrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]fixed_at().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FixedAtrust-analyzer cargo humansize 2.1.3 options/FixedAt#::Baserust-analyzer cargo humansize 2.1.3 options/FixedAt#Base#))
36 .long_unitsrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]long_units().(true);
37 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(2048u32, custom_options), "2048 Bytes");
38
39 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.).fixed_atrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]fixed_at().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FixedAtrust-analyzer cargo humansize 2.1.3 options/FixedAt#::Kilorust-analyzer cargo humansize 2.1.3 options/FixedAt#Kilo#));
40 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(16584975u32, custom_options), "16196.26 KiB");
41 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size_i(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().16584975, custom_options), "-16196.26 KiB");
42
43 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.)
44 .fixed_atrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]fixed_at().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FixedAtrust-analyzer cargo humansize 2.1.3 options/FixedAt#::Terarust-analyzer cargo humansize 2.1.3 options/FixedAt#Tera#))
45 .decimal_placesrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]decimal_places().(10);
46 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(15284975u32, custom_options), "0.0000139016 TiB");
47
48 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((format_size_i(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5500, DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.)), "-5.50 kB");
49 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((format_size(5500u32, DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.)), "5.50 kB");
50
51 let custom_options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.).base_unitrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]base_unit().(BaseUnitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#::Bitrust-analyzer cargo humansize 2.1.3 options/BaseUnit#Bit#);
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((format_size(1usize, custom_options)), "1 bit");
53 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((format_size(150usize, custom_options)), "150 bits");
54 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((format_size(1000usize, custom_options)), "1 kbit");
55 }
56
57 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
58 fn use_custom_option_struct_twicerust-analyzer cargo humansize 2.1.3 use_custom_option_struct_twice().() {
59 let options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.).long_unitsrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]long_units().(true);
60
61 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1500u32, &options), "1.50 Kilobyte",);
62 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(2500u32, &options), "2.50 Kilobytes",);
63 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size_i(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().2500000, &options), "-2.50 Megabytes",);
64 }
65
66 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
67 fn pluralization_worksrust-analyzer cargo humansize 2.1.3 pluralization_works().() {
68 let options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.)
69 .long_unitsrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]long_units().(true)
70 .decimal_zeroesrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]decimal_zeroes().(2);
71
72 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1u32, &options), "1.00 Byte",);
73
74 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000u32, &options), "1.00 Kilobyte",);
75
76 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000000u32, &options), "1.00 Megabyte",);
77
78 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(1000000000u32, &options), "1.00 Gigabyte",);
79
80 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size_i(1000000000000_i64, &options), "1.00 Terabyte",);
81
82 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
83 format_size_i(1000000000000000_i64, &options),
84 "1.00 Petabyte",
85 );
86
87 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
88 format_size_i(1000000000000000000_i64, &options),
89 "1.00 Exabyte",
90 );
91 }
92
93 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
94 fn max_value_decimalrust-analyzer cargo humansize 2.1.3 max_value_decimal().() {
95 let options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(DECIMALrust-analyzer cargo humansize 2.1.3 options/defaults/DECIMAL.)
96 .decimal_placesrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]decimal_places().(7)
97 .long_unitsrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]long_units().(true);
98 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::u64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u64/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u64/MAX., &options), "18.4467441 Exabytes",);
99 }
100
101 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
102 fn max_value_binaryrust-analyzer cargo humansize 2.1.3 max_value_binary().() {
103 let options = FormatSizeOptionsrust-analyzer cargo humansize 2.1.3 options/FormatSizeOptions#::fromrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]from().(BINARYrust-analyzer cargo humansize 2.1.3 options/defaults/BINARY.)
104 .decimal_placesrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]decimal_places().(7)
105 .long_unitsrust-analyzer cargo humansize 2.1.3 options/impl#[FormatSizeOptions]long_units().(true);
106
107 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(format_size(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::u64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u64/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u64/MAX., &options), "16 Exbibytes",);
108 }