File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,34 @@ mod tests {
243
243
244
244
use crate :: blocks:: { BlockSize , SuffixType , to_magnitude_and_suffix} ;
245
245
246
+ #[ test]
247
+ fn test_to_magnitude_and_suffix_rounding ( ) {
248
+ assert_eq ! (
249
+ to_magnitude_and_suffix( 999440 , SuffixType :: Si , true ) ,
250
+ "1.0MB"
251
+ ) ;
252
+ assert_eq ! (
253
+ to_magnitude_and_suffix( 819200 , SuffixType :: Si , true ) ,
254
+ "820kB"
255
+ ) ;
256
+ assert_eq ! (
257
+ to_magnitude_and_suffix( 819936 , SuffixType :: Si , true ) ,
258
+ "820kB"
259
+ ) ;
260
+ assert_eq ! (
261
+ to_magnitude_and_suffix( 818400 , SuffixType :: Si , true ) ,
262
+ "819kB"
263
+ ) ;
264
+ assert_eq ! (
265
+ to_magnitude_and_suffix( 817600 , SuffixType :: Si , true ) ,
266
+ "818kB"
267
+ ) ;
268
+ assert_eq ! (
269
+ to_magnitude_and_suffix( 817200 , SuffixType :: Si , true ) ,
270
+ "818kB"
271
+ ) ;
272
+ }
273
+
246
274
#[ test]
247
275
fn test_to_magnitude_and_suffix_add_tracing_zero ( ) {
248
276
assert_eq ! ( to_magnitude_and_suffix( 1024 , SuffixType :: Iec , true ) , "1.0K" ) ;
Original file line number Diff line number Diff line change @@ -151,6 +151,18 @@ fn test_df_trailing_zeros() {
151
151
. stdout_does_not_match ( & Regex :: new ( "\\ s[1-9][A-Z]" ) . unwrap ( ) ) ;
152
152
}
153
153
154
+ #[ test]
155
+ fn test_df_rounding ( ) {
156
+ use regex:: Regex ;
157
+
158
+ new_ucmd ! ( )
159
+ . arg ( "-H" )
160
+ . arg ( "--output=size,used" )
161
+ . arg ( "--total" )
162
+ . succeeds ( )
163
+ . stdout_does_not_match ( & Regex :: new ( "\\ s\\ d{3}\\ .\\ d[A-Z]" ) . unwrap ( ) ) ;
164
+ }
165
+
154
166
#[ test]
155
167
fn test_df_output_overridden ( ) {
156
168
let expected = if cfg ! ( target_os = "macos" ) {
You can’t perform that action at this time.
0 commit comments