diff options
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index a76b378..c33924d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,12 +25,21 @@ use std::string::ToString; mod locale; fn capitalize(s: &str) -> String { - match s.chars().next() { - Some(ch) => ch.to_uppercase().collect::<String>() + &s[1..], + let mut chars = s.chars(); + match chars.next() { + Some(ch) => ch.to_uppercase().chain(chars).collect::<String>(), None => String::new(), } } +#[test] +fn test_capitalize() { + assert_eq!("Flaccid", capitalize("flaccid")); + assert_eq!("Ångström", capitalize("ångström")); + assert_eq!("Å i lofoten", capitalize("å i lofoten")); + assert_eq!("Ååååh", capitalize("ååååh")); +} + fn print_entry(d: &serde_yaml::Value) { let name = d.get("name").unwrap(); println!("{}", capitalize(name.as_str().unwrap())); |