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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-FileCopyrightText: OpenTalk GmbH <mail@opentalk.eu>
// SPDX-License-Identifier: MIT OR Apache-2.0

use serde::{Deserialize, Serialize};

/// Enum type for defining the possible input file formats
#[derive(
    Debug,
    Clone,
    Copy,
    PartialEq,
    Eq,
    Serialize,
    Deserialize,
    strum::AsRefStr,
    strum::Display,
    strum::EnumCount,
    strum::EnumIter,
    strum::EnumString,
    strum::VariantNames,
    strum::IntoStaticStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum InputFormat {
    /// The MarkDown input format
    Markdown,
}

#[cfg(test)]
mod tests {
    use pretty_assertions::assert_eq;
    use serde_json::json;
    use strum::VariantNames;

    use super::*;

    #[test]
    fn serialize_strum_variant_names() {
        assert_eq!("markdown", InputFormat::Markdown.as_ref());
    }

    #[test]
    fn iterate_strum_variant_names() {
        assert_eq!(["markdown"], InputFormat::VARIANTS);
    }

    #[test]
    fn serialize_json() {
        assert_eq!(
            json!("markdown"),
            serde_json::to_value(InputFormat::Markdown).unwrap()
        );
    }

    #[test]
    fn deserialize_json() {
        assert_eq!(
            InputFormat::Markdown,
            serde_json::from_value(json!("markdown")).unwrap()
        );
    }
}