url_parse/core/
scheme_separator.rs

1#[derive(Debug, PartialEq, Eq)]
2pub enum SchemeSeparator {
3    Colon,
4    ColonSlashSlash,
5}
6
7impl From<SchemeSeparator> for usize {
8    fn from(v: SchemeSeparator) -> usize {
9        match v {
10            SchemeSeparator::Colon => 1,
11            SchemeSeparator::ColonSlashSlash => 3,
12        }
13    }
14}
15
16impl From<SchemeSeparator> for String {
17    fn from(v: SchemeSeparator) -> String {
18        match v {
19            SchemeSeparator::Colon => ":".to_string(),
20            SchemeSeparator::ColonSlashSlash => "://".to_string(),
21        }
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn test_scheme_separator_to_usize_works_when_colon_typical() {
31        let expected = 1;
32        let input = SchemeSeparator::Colon;
33
34        let actual: usize = input.into();
35
36        assert_eq!(actual, expected);
37    }
38
39    #[test]
40    fn test_scheme_separator_to_usize_works_when_colon_slash_slash_typical() {
41        let expected = 3;
42        let input = SchemeSeparator::ColonSlashSlash;
43
44        let actual: usize = input.into();
45
46        assert_eq!(actual, expected);
47    }
48
49    #[test]
50    fn test_scheme_separator_to_string_works_when_colon_typical() {
51        let expected = ":".to_string();
52        let input = SchemeSeparator::Colon;
53
54        let actual: String = input.into();
55
56        assert_eq!(actual, expected);
57    }
58
59    #[test]
60    fn test_scheme_separator_to_string_works_when_colon_slash_slash_typical() {
61        let expected = "://".to_string();
62        let input = SchemeSeparator::ColonSlashSlash;
63
64        let actual: String = input.into();
65
66        assert_eq!(actual, expected);
67    }
68}