From 4e99773a3d203e73b8bf6464490d05649a269fa7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 11 May 2026 02:36:42 +0900 Subject: test(commands): remove per-command tests --- crates/mozart/src/commands/fund.rs | 150 ------------------------------------- 1 file changed, 150 deletions(-) (limited to 'crates/mozart/src/commands/fund.rs') diff --git a/crates/mozart/src/commands/fund.rs b/crates/mozart/src/commands/fund.rs index 677137c..63164c3 100644 --- a/crates/mozart/src/commands/fund.rs +++ b/crates/mozart/src/commands/fund.rs @@ -202,153 +202,3 @@ fn render_json( console_writeln!(io, "{}", &String::from_utf8(ser.into_inner())?); Ok(()) } - -#[cfg(test)] -mod tests { - use super::*; - use mozart_core::console::Console; - - fn make_funding_json(entries: &[(&str, &str)]) -> Vec { - entries - .iter() - .map(|(t, u)| serde_json::json!({"type": t, "url": u})) - .collect() - } - - #[test] - fn insert_funding_data_basic() { - let mut fundings = BTreeMap::new(); - let funding = make_funding_json(&[("github", "https://github.com/Seldaek")]); - insert_funding_data(&mut fundings, "monolog/monolog", &funding); - - let monolog = fundings.get("monolog").unwrap(); - let url = "https://github.com/sponsors/Seldaek"; - let packages = monolog.get(url).unwrap(); - assert_eq!(packages, &vec!["monolog".to_string()]); - } - - #[test] - fn insert_funding_data_skips_empty_url() { - let mut fundings = BTreeMap::new(); - let funding = vec![ - serde_json::json!({"type": "github", "url": ""}), - serde_json::json!({"type": "tidelift"}), - serde_json::json!({"type": "github", "url": "https://github.com/user"}), - ]; - insert_funding_data(&mut fundings, "vendor/pkg", &funding); - - let vendor = fundings.get("vendor").unwrap(); - assert_eq!(vendor.len(), 1); - assert!(vendor.contains_key("https://github.com/sponsors/user")); - } - - #[test] - fn insert_funding_data_skips_malformed_pretty_name() { - let mut fundings = BTreeMap::new(); - let funding = make_funding_json(&[("github", "https://github.com/user")]); - insert_funding_data(&mut fundings, "no-slash-name", &funding); - assert!(fundings.is_empty()); - } - - #[test] - fn insert_funding_data_groups_by_vendor() { - let mut fundings = BTreeMap::new(); - let funding = make_funding_json(&[("github", "https://github.com/fabpot")]); - insert_funding_data(&mut fundings, "symfony/console", &funding); - insert_funding_data(&mut fundings, "symfony/http-kernel", &funding); - - let symfony = fundings.get("symfony").unwrap(); - let url = "https://github.com/sponsors/fabpot"; - let packages = symfony.get(url).unwrap(); - assert_eq!(packages.len(), 2); - assert!(packages.contains(&"console".to_string())); - assert!(packages.contains(&"http-kernel".to_string())); - } - - #[test] - fn insert_funding_data_multiple_urls() { - let mut fundings = BTreeMap::new(); - let funding = vec![ - serde_json::json!({"type": "github", "url": "https://github.com/fabpot"}), - serde_json::json!({ - "type": "tidelift", - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony" - }), - ]; - insert_funding_data(&mut fundings, "symfony/console", &funding); - - let symfony = fundings.get("symfony").unwrap(); - assert_eq!(symfony.len(), 2); - assert!(symfony.contains_key("https://github.com/sponsors/fabpot")); - assert!( - symfony.contains_key("https://tidelift.com/funding/github/packagist/symfony/symfony") - ); - } - - #[test] - fn rewrite_github_url_profile() { - let result = rewrite_github_url("https://github.com/Seldaek", Some("github")); - assert_eq!(result, "https://github.com/sponsors/Seldaek"); - } - - #[test] - fn rewrite_github_url_already_sponsors() { - let result = rewrite_github_url("https://github.com/sponsors/Seldaek", Some("github")); - assert_eq!(result, "https://github.com/sponsors/Seldaek"); - } - - #[test] - fn rewrite_github_url_non_github_type() { - let result = rewrite_github_url("https://github.com/fabpot", Some("tidelift")); - assert_eq!(result, "https://github.com/fabpot"); - } - - #[test] - fn rewrite_github_url_deep_path() { - let result = rewrite_github_url("https://github.com/user/repo", Some("github")); - assert_eq!(result, "https://github.com/user/repo"); - } - - #[test] - fn rewrite_github_url_missing_type() { - let result = rewrite_github_url("https://github.com/user", None); - assert_eq!(result, "https://github.com/user"); - } - - #[test] - fn render_json_empty_emits_array() { - // Composer's `JsonFile::encode([])` emits `[]`; ensure Mozart matches - // rather than serializing the empty BTreeMap to `{}`. - let console = Console::new(0, false, false, false, true); - let fundings: BTreeMap>> = BTreeMap::new(); - - let buf = Vec::new(); - let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); - let mut ser = serde_json::Serializer::with_formatter(buf, formatter); - if fundings.is_empty() { - let empty: Vec<()> = Vec::new(); - empty.serialize(&mut ser).unwrap(); - } else { - fundings.serialize(&mut ser).unwrap(); - } - let out = String::from_utf8(ser.into_inner()).unwrap(); - assert_eq!(out, "[]"); - let _ = console; - } - - #[test] - fn render_json_non_empty_is_object() { - let mut fundings: BTreeMap>> = BTreeMap::new(); - let funding = make_funding_json(&[("github", "https://github.com/Seldaek")]); - insert_funding_data(&mut fundings, "monolog/monolog", &funding); - - let buf = Vec::new(); - let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); - let mut ser = serde_json::Serializer::with_formatter(buf, formatter); - fundings.serialize(&mut ser).unwrap(); - let out = String::from_utf8(ser.into_inner()).unwrap(); - assert!(out.starts_with('{')); - assert!(out.contains("monolog")); - assert!(out.contains("https://github.com/sponsors/Seldaek")); - } -} -- cgit v1.3.1