//! Shared formatting utilities used across TUI screens and commands. /// Format a revenue amount in cents. Returns "$0" for zero. pub fn format_cents(cents: i64) -> String { if cents == 0 { "$0".to_string() } else { format!("${}.{:02}", cents / 100, cents.abs() % 100) } } /// Format an item price in cents. Returns "Free" for zero. pub fn format_price(cents: i32) -> String { if cents == 0 { "Free".to_string() } else { format!("${}.{:02}", cents / 100, cents % 100) } } /// Human-readable creator tier label. pub fn format_tier(tier: &str) -> &str { match tier { "basic" => "Basic", "small_files" => "Small Files", "big_files" => "Big Files", "everything" => "Everything", _ => tier, } } /// Human-readable project type label. pub fn format_project_type(pt: &str) -> &str { match pt { "software" => "Software", "music" => "Music", "blog" => "Blog", "video" => "Video", "audio" => "Audio", "art" => "Art", "writing" => "Writing", "education" => "Education", other => other, } } /// Human-readable item type label. pub fn format_item_type(it: &str) -> &str { match it { "audio" => "Audio", "text" => "Text", "video" => "Video", "image" => "Image", "plugin" => "Plugin", "preset" => "Preset", "sample" => "Sample", "course" => "Course", "template" => "Template", "digital" => "Digital", "bundle" => "Bundle", other => other, } } #[cfg(test)] mod tests { use super::*; #[test] fn format_cents_zero() { assert_eq!(format_cents(0), "$0"); } #[test] fn format_cents_positive() { assert_eq!(format_cents(999), "$9.99"); assert_eq!(format_cents(100), "$1.00"); assert_eq!(format_cents(1050), "$10.50"); } #[test] fn format_price_free() { assert_eq!(format_price(0), "Free"); } #[test] fn format_price_nonzero() { assert_eq!(format_price(550), "$5.50"); assert_eq!(format_price(1299), "$12.99"); } #[test] fn format_tier_known() { assert_eq!(format_tier("basic"), "Basic"); assert_eq!(format_tier("small_files"), "Small Files"); assert_eq!(format_tier("everything"), "Everything"); } #[test] fn format_tier_unknown() { assert_eq!(format_tier("custom"), "custom"); } #[test] fn format_project_type_known() { assert_eq!(format_project_type("software"), "Software"); assert_eq!(format_project_type("music"), "Music"); } #[test] fn format_item_type_known() { assert_eq!(format_item_type("audio"), "Audio"); assert_eq!(format_item_type("plugin"), "Plugin"); } #[test] fn format_item_type_unknown() { assert_eq!(format_item_type("other_thing"), "other_thing"); } }