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
//! Parsers extract relevent package names from each line of an output from an `apt-cache` command.

pub fn search(s: &str) -> Option<&str> {
    s.split_whitespace().next()
}

pub fn depends(s: &str) -> Option<&str> {
    s.trim().strip_prefix("Depends: ")
}

pub fn recommends(s: &str) -> Option<&str> {
    s.trim().strip_prefix("Recommends: ")
}

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

    #[test]
    fn test_search() {
        assert_eq!(
            search("package_name long description").unwrap(),
            "package_name"
        )
    }

    #[test]
    fn test_depends() {
        assert_eq!(depends("  Depends: debianutils").unwrap(), "debianutils");
        assert!(depends("bash").is_none())
    }
}