/// Trims a feed URL entered by the user, returning `None` when it's blank /// so the submit handler can bail out before making a request. pub fn normalize_feed_url(input: &str) -> Option { let trimmed = input.trim(); if trimmed.is_empty() { None } else { Some(trimmed.to_string()) } } /// Success message shown after a feed subscription pulls in new articles. pub fn subscribed_message(article_count: usize) -> String { format!("Subscribed — pulled in {article_count} article(s).") } #[cfg(test)] mod tests { use super::*; #[test] fn blank_input_normalizes_to_none() { assert_eq!(normalize_feed_url(""), None); assert_eq!(normalize_feed_url(" "), None); } #[test] fn surrounding_whitespace_is_trimmed() { assert_eq!( normalize_feed_url(" https://example.com/feed.xml "), Some("https://example.com/feed.xml".to_string()) ); } #[test] fn message_reports_the_article_count() { assert_eq!( subscribed_message(0), "Subscribed — pulled in 0 article(s)." ); assert_eq!( subscribed_message(3), "Subscribed — pulled in 3 article(s)." ); } }