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
/// Translation state.
///
/// Indicates whether the translation is considered usable.
///
/// # TODO:
/// - Rejected, Unreviewed, NeedsReview (from TT), possibly more (note: obsolete is a separate flag)
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum State {
    /// The unit is not translated.
    Empty,
    /// The unit is a suggestion that might be embarrassingly wrong, possibly automatic. It needs
    /// checking by human translator before it can be used. (Used for `#,fuzzy` entries in `.po`.)
    NeedsWork,
    /// The unit is considered usable.
    Final,
}

impl Default for State {
    fn default() -> State {
        State::Empty
    }
}

// no-coverage:start
#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashMap;

    #[test]
    fn test_enum() {
        assert_eq!(State::Empty.clone(), State::Empty);
        assert_eq!(State::NeedsWork.clone(), State::NeedsWork);
        assert_eq!(State::Final.clone(), State::Final);
    }

    #[test]
    fn test_default() {
        assert_eq!(State::default(), State::Empty);
        assert_eq!(format!("{:?}", State::default()), String::from("Empty"));
    }

    #[test]
    fn test_hash() {
        let m = {
            let mut m = HashMap::new();

            m.insert(State::Empty, 123);
            m
        };

        assert_eq!(m.get(&State::Final), None);
        assert_eq!(m.get(&State::Empty), Some(&123));
    }
}
// no-coverage:stop