diff --git a/src/utils/mod.rs b/src/utils/mod.rs index d1b3fb0..4d08202 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -21,8 +21,9 @@ pub fn cut(input: &str, sep: u8) -> (&str, &str) { } } -pub(crate) fn to_lowercase(s: Cow) -> Cow { - if !s.chars().any(|c| c.is_uppercase()) { +pub(crate) fn to_lowercase<'a>(s: impl Into>) -> Cow<'a, str> { + let s = s.into(); + if s.chars().any(|c| c.is_uppercase()) { Cow::Owned(s.to_lowercase()) } else { s @@ -47,4 +48,13 @@ mod tests { assert_eq!(rcut(buf, b':'), ("A:B", "C")); assert_eq!(rcut(buf, b','), ("", "A:B:C")); } + + #[test] + fn to_lowercase_simple() { + assert_eq!(to_lowercase("foo"), "foo"); + assert_eq!(to_lowercase("Foo"), "foo"); + assert_eq!(to_lowercase("FoO"), "foo"); + assert_eq!(to_lowercase("fOo"), "foo"); + assert_eq!(to_lowercase("FOO"), "foo"); + } }