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
64
65
66
67
68
#[derive(Debug, PartialEq, Eq)]
pub enum SchemeSeparator {
    Colon,
    ColonSlashSlash,
}

impl From<SchemeSeparator> for usize {
    fn from(v: SchemeSeparator) -> usize {
        match v {
            SchemeSeparator::Colon => 1,
            SchemeSeparator::ColonSlashSlash => 3,
        }
    }
}

impl From<SchemeSeparator> for String {
    fn from(v: SchemeSeparator) -> String {
        match v {
            SchemeSeparator::Colon => ":".to_string(),
            SchemeSeparator::ColonSlashSlash => "://".to_string(),
        }
    }
}

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

    #[test]
    fn test_scheme_separator_to_usize_works_when_colon_typical() {
        let expected = 1;
        let input = SchemeSeparator::Colon;

        let actual: usize = input.into();

        assert_eq!(actual, expected);
    }

    #[test]
    fn test_scheme_separator_to_usize_works_when_colon_slash_slash_typical() {
        let expected = 3;
        let input = SchemeSeparator::ColonSlashSlash;

        let actual: usize = input.into();

        assert_eq!(actual, expected);
    }

    #[test]
    fn test_scheme_separator_to_string_works_when_colon_typical() {
        let expected = ":".to_string();
        let input = SchemeSeparator::Colon;

        let actual: String = input.into();

        assert_eq!(actual, expected);
    }

    #[test]
    fn test_scheme_separator_to_string_works_when_colon_slash_slash_typical() {
        let expected = "://".to_string();
        let input = SchemeSeparator::ColonSlashSlash;

        let actual: String = input.into();

        assert_eq!(actual, expected);
    }
}