extern crate libzettels;
extern crate tempfile;
use self::tempfile::tempdir;
use libzettels::{Config, Index, IndexingMethod};
use libzettels::examples::*;
use std::io::Write;
const FILE7: &str ="# A totally unrelated file, which just happens to be in
the working directory and also happens to contain a markdown link to a file
that is not [contained in the zettelkasten](unrelated_file.md).";
#[test]
fn test_empty_update_markdown_in_cwd_ripgrep() {
empty_update_markdown_in_cwd(IndexingMethod::RipGrep);
}
#[test]
fn test_empty_update_markdown_in_cwd_grep() {
empty_update_markdown_in_cwd(IndexingMethod::Grep);
}
#[test]
fn test_empty_update_markdown_in_cwd_native() {
empty_update_markdown_in_cwd(IndexingMethod::Native);
}
fn empty_update_markdown_in_cwd(indexingmethod: IndexingMethod) {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_examples_with_index(dir).expect("Failed to generate examples");
let config_dir = dir.join("examples/config");
let cfg_file = config_dir.join("libzettels.cfg.yaml");
let mut cfg = Config::from_file(cfg_file).expect("Failed to load config");
cfg.indexingmethod = indexingmethod;
let mut index = Index::load(&cfg).expect("Failed to load index");
let working_dir = dir.join("foo");
std::fs::create_dir_all(&working_dir)
.expect("Failed to create working dir");
let mut forbidden_file = std::fs::File::create(&working_dir
.join("forbidden.md"))
.expect("Failed to create forbidden.md");
writeln!(forbidden_file, "{}", FILE7).expect("Failed to write to file");
std::env::set_current_dir(&working_dir).expect("Failed to enter working dir");
let r = index.update(&cfg);
assert!(r.is_ok());
}