use core::cmp::Ordering;
#[inline]
pub const fn eq(a: &str, b: &str) -> bool {
a.eq_ignore_ascii_case(b)
}
#[inline]
pub fn cmp(a: &str, second: &str) -> Ordering {
a.bytes()
.map(|byte| byte.to_ascii_lowercase())
.cmp(second.bytes().map(|byte| byte.to_ascii_lowercase()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn eq_same() {
assert!(eq("location", "location"));
}
#[test]
fn eq_diff_case() {
assert!(eq("Location", "LOCATION"));
assert!(eq("apiVersion", "APIversion"));
}
#[test]
fn eq_not_equal() {
assert!(!eq("name", "type"));
}
#[test]
fn eq_empty() {
assert!(eq("", ""));
assert!(!eq("", "a"));
}
#[test]
fn cmp_equal() {
assert_eq!(cmp("Location", "location"), Ordering::Equal);
}
#[test]
fn cmp_less() {
assert_eq!(cmp("apiVersion", "Name"), Ordering::Less);
}
#[test]
fn cmp_greater() {
assert_eq!(cmp("type", "Name"), Ordering::Greater);
}
}