Skip to main content

es_fluent_shared/
mode.rs

1/// The mode to use when parsing Fluent files.
2#[derive(
3    Clone,
4    Copy,
5    Debug,
6    Default,
7    strum::Display,
8    strum::IntoStaticStr,
9    Eq,
10    PartialEq,
11    clap::ValueEnum,
12    serde::Deserialize,
13    serde::Serialize,
14)]
15#[serde(rename_all = "snake_case")]
16#[strum(const_into_str, serialize_all = "snake_case")]
17pub enum FluentParseMode {
18    /// Overwrite existing translations.
19    Aggressive,
20    /// Preserve existing translations.
21    #[default]
22    Conservative,
23}
24
25impl FluentParseMode {
26    pub const fn label(self) -> &'static str {
27        self.into_str()
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::FluentParseMode;
34
35    #[test]
36    fn fluent_parse_mode_labels_use_const_static_str_mapping() {
37        const CONSERVATIVE_LABEL: &str = FluentParseMode::Conservative.label();
38
39        assert_eq!(CONSERVATIVE_LABEL, "conservative");
40        assert_eq!(FluentParseMode::Aggressive.label(), "aggressive");
41    }
42}