~savoy/mailcap

9269e27cea2765b7d97a707bab450c2b11a1710a — savoy 2 years ago 060c85b
test cleanup 81% coverage

Signed-off-by: savoy <git@liberation.red>
1 files changed, 41 insertions(+), 2 deletions(-)

M src/lib.rs
M src/lib.rs => src/lib.rs +41 -2
@@ 284,11 284,38 @@ mod tests {
        (path, dummy_value)
    }

    fn dummy_mailcap() -> Mailcap {
        let mut cap_data: HashMap<String, Entry> = HashMap::new();
        cap_data.insert(
            "text/html".to_string(),
            Entry {
                mime_type: "text/html".to_string(),
                command: "qutebrowser '%s'".to_string(),
                compose: None,
                compose_typed: None,
                edit: None,
                print: None,
                test: Some("test -n \"$DISPLAY\"".to_string()),
                note: None,
                description: None,
                name_template: Some("%s.html".to_string()),
                needs_terminal: true,
                copious_output: false,
                textual_new_lines: true,
            },
        );
        Mailcap {
            files: vec![PathBuf::from("/etc/mailcap")],
            data: cap_data,
        }
    }

    #[test]
    #[serial]
    fn mailcap_files_env() {
        env::set_var("MAILCAPS", "/etc/mailcap");
        let mailcaps = Mailcap::list_potential_files();
        env::remove_var("MAILCAPS");

        assert_eq!(mailcaps, vec![PathBuf::from("/etc/mailcap")]);
    }


@@ 313,8 340,6 @@ mod tests {

    #[test]
    fn mailcap_lines() {
        env::remove_var("MAILCAPS");

        let home = Mailcap::get_user_home();
        let local_location = home.join(".mailcap");



@@ 393,6 418,7 @@ mod tests {

        env::set_var("MAILCAPS", "/tmp/mailcap-rs.test");
        let mailcap = Mailcap::new().unwrap();
        env::remove_var("MAILCAPS");
        if let Some(i) = mailcap.data.get("text/html") {
            assert_eq!(i.command, dummy_line.command)
        }


@@ 412,8 438,21 @@ mod tests {

        env::set_var("MAILCAPS", "/tmp/mailcap-rs.test");
        let mailcap = Mailcap::new().unwrap();
        env::remove_var("MAILCAPS");
        if let Some(i) = mailcap.data.get("text/html") {
            assert_eq!(i.command, dummy_line.command)
        }
    }

    #[test]
    fn get_mailcap_success() {
        let mailcap = dummy_mailcap();
        assert!(mailcap.get("text/html").is_some())
    }

    #[test]
    fn get_mailcap_failure() {
        let mailcap = dummy_mailcap();
        assert!(mailcap.get("image/jpeg").is_none())
    }
}