fallow_config/config/
format.rs1#[derive(Debug, Default, Clone, Copy)]
5pub enum OutputFormat {
6 #[default]
8 Human,
9 Json,
11 Sarif,
13 Compact,
15 Markdown,
17 CodeClimate,
21 PrCommentGithub,
23 PrCommentGitlab,
25 ReviewGithub,
27 ReviewGitlab,
29 Badge,
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn output_format_default_is_human() {
39 let format = OutputFormat::default();
40 assert!(matches!(format, OutputFormat::Human));
41 }
42
43 #[test]
44 fn output_format_all_variants_constructible() {
45 assert!(matches!(OutputFormat::Human, OutputFormat::Human));
46 assert!(matches!(OutputFormat::Json, OutputFormat::Json));
47 assert!(matches!(OutputFormat::Sarif, OutputFormat::Sarif));
48 assert!(matches!(OutputFormat::Compact, OutputFormat::Compact));
49 assert!(matches!(OutputFormat::Markdown, OutputFormat::Markdown));
50 assert!(matches!(
51 OutputFormat::CodeClimate,
52 OutputFormat::CodeClimate
53 ));
54 assert!(matches!(
55 OutputFormat::PrCommentGithub,
56 OutputFormat::PrCommentGithub
57 ));
58 assert!(matches!(
59 OutputFormat::PrCommentGitlab,
60 OutputFormat::PrCommentGitlab
61 ));
62 assert!(matches!(
63 OutputFormat::ReviewGithub,
64 OutputFormat::ReviewGithub
65 ));
66 assert!(matches!(
67 OutputFormat::ReviewGitlab,
68 OutputFormat::ReviewGitlab
69 ));
70 assert!(matches!(OutputFormat::Badge, OutputFormat::Badge));
71 }
72
73 #[test]
74 fn output_format_debug_impl() {
75 let human = format!("{:?}", OutputFormat::Human);
76 assert_eq!(human, "Human");
77 let json = format!("{:?}", OutputFormat::Json);
78 assert_eq!(json, "Json");
79 let sarif = format!("{:?}", OutputFormat::Sarif);
80 assert_eq!(sarif, "Sarif");
81 let compact = format!("{:?}", OutputFormat::Compact);
82 assert_eq!(compact, "Compact");
83 let markdown = format!("{:?}", OutputFormat::Markdown);
84 assert_eq!(markdown, "Markdown");
85 let codeclimate = format!("{:?}", OutputFormat::CodeClimate);
86 assert_eq!(codeclimate, "CodeClimate");
87 let pr_comment_github = format!("{:?}", OutputFormat::PrCommentGithub);
88 assert_eq!(pr_comment_github, "PrCommentGithub");
89 let pr_comment_gitlab = format!("{:?}", OutputFormat::PrCommentGitlab);
90 assert_eq!(pr_comment_gitlab, "PrCommentGitlab");
91 let review_github = format!("{:?}", OutputFormat::ReviewGithub);
92 assert_eq!(review_github, "ReviewGithub");
93 let review_gitlab = format!("{:?}", OutputFormat::ReviewGitlab);
94 assert_eq!(review_gitlab, "ReviewGitlab");
95 let badge = format!("{:?}", OutputFormat::Badge);
96 assert_eq!(badge, "Badge");
97 }
98
99 #[test]
100 fn output_format_copy() {
101 let original = OutputFormat::Json;
102 let copied = original;
103 assert!(matches!(copied, OutputFormat::Json));
104 assert!(matches!(original, OutputFormat::Json));
105 }
106
107 #[test]
108 #[expect(
109 clippy::clone_on_copy,
110 reason = "explicitly testing the Clone impl for coverage"
111 )]
112 fn output_format_clone_all_variants() {
113 let variants = [
114 OutputFormat::Human,
115 OutputFormat::Json,
116 OutputFormat::Sarif,
117 OutputFormat::Compact,
118 OutputFormat::Markdown,
119 OutputFormat::CodeClimate,
120 OutputFormat::PrCommentGithub,
121 OutputFormat::PrCommentGitlab,
122 OutputFormat::ReviewGithub,
123 OutputFormat::ReviewGitlab,
124 OutputFormat::Badge,
125 ];
126 for variant in variants {
127 let cloned = variant.clone();
128 assert_eq!(format!("{cloned:?}"), format!("{variant:?}"));
129 }
130 }
131
132 #[test]
133 #[expect(
134 clippy::clone_on_copy,
135 reason = "explicitly testing the Clone impl for coverage"
136 )]
137 fn output_format_clone_preserves_variant() {
138 let badge = OutputFormat::Badge;
139 let cloned = badge.clone();
140 assert!(matches!(cloned, OutputFormat::Badge));
141
142 let codeclimate = OutputFormat::CodeClimate;
143 let cloned = codeclimate.clone();
144 assert!(matches!(cloned, OutputFormat::CodeClimate));
145 }
146
147 #[test]
148 fn output_format_default_matches_human_debug() {
149 assert_eq!(format!("{:?}", OutputFormat::default()), "Human");
150 }
151
152 #[test]
153 fn output_format_variants_are_distinct() {
154 let debug_strings: Vec<String> = [
155 OutputFormat::Human,
156 OutputFormat::Json,
157 OutputFormat::Sarif,
158 OutputFormat::Compact,
159 OutputFormat::Markdown,
160 OutputFormat::CodeClimate,
161 OutputFormat::PrCommentGithub,
162 OutputFormat::PrCommentGitlab,
163 OutputFormat::ReviewGithub,
164 OutputFormat::ReviewGitlab,
165 OutputFormat::Badge,
166 ]
167 .iter()
168 .map(|v| format!("{v:?}"))
169 .collect();
170
171 for (i, a) in debug_strings.iter().enumerate() {
172 for (j, b) in debug_strings.iter().enumerate() {
173 if i != j {
174 assert_ne!(
175 a, b,
176 "variants at index {i} and {j} have the same debug output"
177 );
178 }
179 }
180 }
181 }
182}