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
69
70
71
72
73
74
75
76
use crate::url::Parser;
use crate::utils::Utils;

impl Parser {
    pub fn mixout_path<'a>(&self, input: &str) -> Option<Vec<String>> {
        let input = Utils::substring_from_path_begin(self, input);
        let input = Utils::substring_after_port(self, input);
        let input = match input.chars().nth(0) {
            Some('/') => &input[1..],
            _ => &input,
        };
        let position_questionmark = input.find("?");
        let path_string = match position_questionmark {
            Some(v) => &input[..v],
            None => input,
        };
        return Some(
            path_string
                .split("/")
                .map(|s| s.to_string())
                .collect::<Vec<String>>(),
        );
    }
}

#[test]
fn test_mixout_path_works_when_partial_url() {
    use crate::url::*;
    let input = "https://www.example.co.uk/blog/article/search?docid=720&hl=en#dayone";
    let result = Parser::new(None).mixout_path(input).unwrap();
    let expected = vec![
        "blog".to_string(),
        "article".to_string(),
        "search".to_string(),
    ];
    assert_eq!(result, expected);
}

#[test]
fn test_mixout_path_works_when_partial_url_starts_with_slash() {
    use crate::url::*;
    let input = "https://www.example.co.uk/blog/article/search?docid=720&hl=en#dayone";
    let result = Parser::new(None).mixout_path(input).unwrap();
    let expected = vec![
        "blog".to_string(),
        "article".to_string(),
        "search".to_string(),
    ];
    assert_eq!(result, expected);
}

#[test]
fn test_mixout_path_works_when_typical() {
    use crate::url::*;
    let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
    let result = Parser::new(None).mixout_path(input).unwrap();
    let expected = vec![
        "blog".to_string(),
        "article".to_string(),
        "search".to_string(),
    ];
    assert_eq!(result, expected);
}

#[test]
fn test_mixout_path_works_when_no_port() {
    use crate::url::*;
    let input = "https://www.example.co.uk/blog/article/search?docid=720&hl=en#dayone";
    let result = Parser::new(None).mixout_path(input).unwrap();
    let expected = vec![
        "blog".to_string(),
        "article".to_string(),
        "search".to_string(),
    ];
    assert_eq!(result, expected);
}