aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/pane_frame_style.rs
blob: 392f2e89f06fdc437a61c391fdb595a38950a82e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pub use super::generated_api::api::pane_frame_style::PaneFrameStyle as ProtobufPaneFrameStyle;
use crate::input::options::PaneFrameStyle;

use std::convert::TryFrom;

impl TryFrom<ProtobufPaneFrameStyle> for PaneFrameStyle {
    type Error = &'static str;
    fn try_from(protobuf_pane_frame_style: ProtobufPaneFrameStyle) -> Result<Self, &'static str> {
        match protobuf_pane_frame_style {
            ProtobufPaneFrameStyle::Full => Ok(PaneFrameStyle::Full),
            ProtobufPaneFrameStyle::Titles => Ok(PaneFrameStyle::Titles),
            ProtobufPaneFrameStyle::None => Ok(PaneFrameStyle::None),
        }
    }
}

impl TryFrom<PaneFrameStyle> for ProtobufPaneFrameStyle {
    type Error = &'static str;
    fn try_from(pane_frame_style: PaneFrameStyle) -> Result<Self, &'static str> {
        Ok(match pane_frame_style {
            PaneFrameStyle::Full => ProtobufPaneFrameStyle::Full,
            PaneFrameStyle::Titles => ProtobufPaneFrameStyle::Titles,
            PaneFrameStyle::None => ProtobufPaneFrameStyle::None,
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn pane_frame_style_roundtrips_through_protobuf() {
        for style in [
            PaneFrameStyle::Full,
            PaneFrameStyle::Titles,
            PaneFrameStyle::None,
        ] {
            let protobuf: ProtobufPaneFrameStyle = style.try_into().unwrap();
            let roundtripped: PaneFrameStyle = protobuf.try_into().unwrap();
            assert_eq!(style, roundtripped);
        }
    }

    #[test]
    fn unknown_pane_frame_style_value_is_rejected() {
        assert!(ProtobufPaneFrameStyle::from_i32(99).is_none());
    }
}