1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #8069 from cakebaker/uptime_use_plural_for_zero_users

uptime: use "0 users" instead of "0 user"
This commit is contained in:
Sylvestre Ledru 2025-06-07 09:37:10 +02:00 committed by GitHub
commit 320dcd114c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -302,13 +302,13 @@ pub fn get_nusers() -> usize {
///
/// # Returns
///
/// e.g. "0 user", "1 user", "2 users"
/// e.g. "0 users", "1 user", "2 users"
#[inline]
pub fn format_nusers(nusers: usize) -> String {
match nusers {
0 => "0 user".to_string(),
1 => "1 user".to_string(),
_ => format!("{nusers} users"),
pub fn format_nusers(n: usize) -> String {
if n == 1 {
String::from("1 user")
} else {
format!("{n} users")
}
}
@ -373,3 +373,15 @@ pub fn get_formatted_loadavg() -> UResult<String> {
loadavg.0, loadavg.1, loadavg.2
))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_format_nusers() {
assert_eq!("0 users", format_nusers(0));
assert_eq!("1 user", format_nusers(1));
assert_eq!("2 users", format_nusers(2));
}
}