File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
src/uucore/src/lib/features Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -302,13 +302,13 @@ pub fn get_nusers() -> usize {
302
302
///
303
303
/// # Returns
304
304
///
305
- /// e.g. "0 user ", "1 user", "2 users"
305
+ /// e.g. "0 users ", "1 user", "2 users"
306
306
#[ inline]
307
- pub fn format_nusers ( nusers : usize ) -> String {
308
- match nusers {
309
- 0 => "0 user". to_string ( ) ,
310
- 1 => "1 user" . to_string ( ) ,
311
- _ => format ! ( "{nusers } users" ) ,
307
+ pub fn format_nusers ( n : usize ) -> String {
308
+ if n == 1 {
309
+ String :: from ( "1 user")
310
+ } else {
311
+ format ! ( "{n } users" )
312
312
}
313
313
}
314
314
@@ -373,3 +373,15 @@ pub fn get_formatted_loadavg() -> UResult<String> {
373
373
loadavg. 0 , loadavg. 1 , loadavg. 2
374
374
) )
375
375
}
376
+
377
+ #[ cfg( test) ]
378
+ mod tests {
379
+ use super :: * ;
380
+
381
+ #[ test]
382
+ fn test_format_nusers ( ) {
383
+ assert_eq ! ( "0 users" , format_nusers( 0 ) ) ;
384
+ assert_eq ! ( "1 user" , format_nusers( 1 ) ) ;
385
+ assert_eq ! ( "2 users" , format_nusers( 2 ) ) ;
386
+ }
387
+ }
You can’t perform that action at this time.
0 commit comments