~savoy/mailcap

6b8eb21ece44e3a381c7ade9dea84719e1dff3e3 — savoy 2 years ago 4bbfb1b
testing of pub fn Mailcap::new

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

M src/lib.rs
M src/lib.rs => src/lib.rs +24 -0
@@ 212,6 212,16 @@ impl Entry {
mod tests {
    use super::*;
    use serial_test::serial;
    use std::io::Write;

    fn create_dummy_mailcap_line() -> (PathBuf, String) {
        let path = PathBuf::from("/tmp/mailcap-rs.test");
        let mut dummy_file = File::create(&path).unwrap();
        let dummy_value = String::from("text/html; qutebrowser '%s'; test=test -n \"$DISPLAY\"; nametemplate=%s.html; needsterminal");
        write!(&mut dummy_file, "{}", dummy_value).unwrap();

        (path, dummy_value)
    }

    #[test]
    #[serial]


@@ 314,4 324,18 @@ mod tests {
            entry
        )
    }

    #[test]
    #[serial]
    fn create_mailcap_struct() {
        let (_path, dummy_line) = create_dummy_mailcap_line();
        let dummy_line_vectorized = Mailcap::parse_valid_lines(vec![dummy_line]).unwrap();
        let dummy_line = Entry::from(dummy_line_vectorized[0].to_owned());

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