| 1 | use super::*; |
| 2 | |
| 3 | fn sample_pr() -> GhPullRequest { |
| 4 | GhPullRequest { |
| 5 | title: "Add cool feature".to_string(), |
| 6 | body: "Closes #99.\n\nAlso:\n- bullet a\n- bullet b".to_string(), |
| 7 | base: "main".to_string(), |
| 8 | head: "feat/cool".to_string(), |
| 9 | url: "https://github.com/example/repo/pull/123".to_string(), |
| 10 | head_sha: "abc123def456abc123def456abc123def456abc1".to_string(), |
| 11 | ..GhPullRequest::default() |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | #[test] |
| 16 | fn format_pr_prompt_includes_title_url_branches_body_and_diff() { |
| 17 | let prompt = format_pr_prompt(123, &sample_pr(), "diff --git a/x b/x\n+y"); |
| 18 | assert!(prompt.contains("Review PR #123 — Add cool feature")); |
| 19 | assert!(prompt.contains("URL: https://github.com/example/repo/pull/123")); |
| 20 | assert!(prompt.contains("Branches: main ← feat/cool")); |
| 21 | assert!(prompt.contains("Closes #99.")); |
| 22 | assert!(prompt.contains("- bullet a")); |
| 23 | assert!(prompt.contains("```diff")); |
| 24 | assert!(prompt.contains("diff --git a/x b/x")); |
| 25 | } |
| 26 | |
| 27 | #[test] |
| 28 | fn format_pr_prompt_handles_empty_body_and_unknown_branches() { |
| 29 | let pr = GhPullRequest { |
| 30 | title: String::new(), |
| 31 | body: " ".to_string(), |
| 32 | base: String::new(), |
| 33 | head: String::new(), |
| 34 | url: String::new(), |
| 35 | head_sha: String::new(), |
| 36 | ..GhPullRequest::default() |
| 37 | }; |
| 38 | let prompt = format_pr_prompt(7, &pr, "(diff body)"); |
| 39 | assert!(prompt.contains("(PR #7)")); |
| 40 | assert!(prompt.contains("(no description)")); |
| 41 | assert!(prompt.contains("Branches: (unknown)")); |
| 42 | assert!(prompt.contains("URL: (unavailable)")); |
| 43 | } |
| 44 | |
| 45 | #[test] |
| 46 | fn format_pr_prompt_preserves_an_admitted_unicode_diff() { |
| 47 | let mut diff = "X".repeat(190 * 1024); |
| 48 | diff.push_str(&"🚀".repeat(5_000)); |
| 49 | let prompt = format_pr_prompt(1, &sample_pr(), &diff); |
| 50 | assert!(prompt.contains(&diff)); |
| 51 | assert!(!prompt.contains("diff truncated")); |
| 52 | } |
| 53 | |
| 54 | #[test] |
| 55 | fn is_command_available_detects_present_and_absent_binaries() { |
| 56 | #[cfg(unix)] |
| 57 | assert!(is_command_available("sh"), "POSIX `sh` should be on PATH"); |
| 58 | |
| 59 | assert!( |
| 60 | !is_command_available("this-command-cannot-exist-codewhale-tui-test-ENOENT-marker"), |
| 61 | "missing command should return false, not panic" |
| 62 | ); |
| 63 | } |
| 64 |