Skip to main content

cfgd_core/output/
role.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4#[serde(rename_all = "lowercase")]
5pub enum Role {
6    Ok,
7    Warn,
8    Fail,
9    Pending,
10    Running,
11    Skipped,
12    Info,
13    /// "Attention without alarm" — a terminal-positive notable change that does
14    /// not warrant `Warn` severity. Mirrors `gh merged`, cargo's `Running`,
15    /// homebrew's yellow-bg new-formula highlight. Suppressed at `Verbosity::Quiet`.
16    Accent,
17    /// "Structural pivot / label / identifier" — names a thing (a source, a
18    /// scope, a module-kind) rather than carrying severity. Mirrors brew's
19    /// `==>` bold-blue, kubecolor's resource-kind magenta. Suppressed at
20    /// `Verbosity::Quiet`.
21    Secondary,
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn role_serializes_lowercase() {
30        let json = serde_json::to_string(&Role::Ok).unwrap();
31        assert_eq!(json, "\"ok\"");
32        let json = serde_json::to_string(&Role::Fail).unwrap();
33        assert_eq!(json, "\"fail\"");
34    }
35
36    #[test]
37    fn role_round_trips() {
38        for r in [
39            Role::Ok,
40            Role::Warn,
41            Role::Fail,
42            Role::Pending,
43            Role::Running,
44            Role::Skipped,
45            Role::Info,
46            Role::Accent,
47            Role::Secondary,
48        ] {
49            let s = serde_json::to_string(&r).unwrap();
50            let back: Role = serde_json::from_str(&s).unwrap();
51            assert_eq!(r, back);
52        }
53    }
54
55    #[test]
56    fn accent_and_secondary_serialize_lowercase() {
57        assert_eq!(serde_json::to_string(&Role::Accent).unwrap(), "\"accent\"");
58        assert_eq!(
59            serde_json::to_string(&Role::Secondary).unwrap(),
60            "\"secondary\""
61        );
62    }
63}