Add trailing zeros for discriminators with tests

main
Elnu 1 year ago
parent 74b0e6141a
commit 9e0371b6ac

@ -22,7 +22,32 @@ impl User for serenity::User {
if self.discriminator == 0 { if self.discriminator == 0 {
return self.name.clone(); return self.name.clone();
} }
format!("{}#{}", self.name, self.discriminator) format!("{}#{:0>4}", self.name, self.discriminator)
}
}
#[cfg(test)]
mod tests {
use crate::serenity::User;
use crate::utils::User as UserTrait;
fn test_user(name: &str, discriminator: u16) -> User {
let mut user = User::default();
user.name = name.to_owned();
user.discriminator = discriminator;
user
}
#[test]
fn test_legacy_username() {
let user = test_user("test", 123);
assert_eq!(user.username(), "test#0123");
}
#[test]
fn test_new_username() {
let user = test_user("test", 0);
assert_eq!(user.username(), "test");
} }
} }

Loading…
Cancel
Save