//! Custom Askama filters.

/// Returns `singular` if `count == 1`, otherwise `plural`.
pub fn pluralize(count: &usize, singular: &str, plural: &str) -> askama::Result<String> {
    Ok(if *count == 1 {
        singular.to_string()
    } else {
        plural.to_string()
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn pluralize_singular() {
        assert_eq!(pluralize(&1, "item", "items").unwrap(), "item");
    }

    #[test]
    fn pluralize_zero() {
        assert_eq!(pluralize(&0, "item", "items").unwrap(), "items");
    }

    #[test]
    fn pluralize_multiple() {
        assert_eq!(pluralize(&3, "item", "items").unwrap(), "items");
    }
}
