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
pub mod init;
pub use self::init::{init, InitOptions};
pub mod add;
pub mod commit;
pub mod new;
pub mod open;

#[cfg(test)]
pub mod testing {
    use std::path::PathBuf;

    use chrono::prelude::*;
    use tempfile::tempdir;

    use super::{init, InitOptions};
    use crate::{
        config::Config,
        ops::new::{new, NewOptions},
        utils::editing::test::test_string_getter,
    };

    pub fn temp_path() -> PathBuf {
        tempdir().unwrap().path().to_path_buf()
    }

    pub fn temp_diary_path() -> PathBuf {
        let dir = temp_path();
        dir.join("diary")
    }

    pub fn temp_config() -> Config {
        let diary_dir = temp_diary_path();
        Config::builder().diary_path(diary_dir).build()
    }

    pub fn new_entry(config: &Config, entry_date: &Date<Local>) {
        let new_opts = NewOptions { open: false };
        new(&new_opts, config, entry_date, test_string_getter).unwrap();
    }

    pub fn default_init(config: &Config) {
        let init_opts = InitOptions {
            path: temp_path(),
            prefix: None,
            git_repo: false,
        };
        init(&init_opts, config).unwrap();
    }
}