extern crate libzettels;
extern crate tempfile;
use self::tempfile::tempdir;
use libzettels::{Config, Index, IndexingMethod};
use libzettels::examples::*;
use std::path::PathBuf;
#[test]
fn test_gitignore_grep() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::Grep;
let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 7);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
}
#[test]
fn test_gitignore_ripgrep() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::RipGrep;
let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 7);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
}
#[test]
fn test_gitignore_native() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::Native;
let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 7);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
}
#[test]
fn test_zettelsignore_grep() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::Grep;
cfg.ignorefile = PathBuf::from(".zettelsignore");
let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 7);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
}
#[test]
fn test_zettelsignore_ripgrep() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::RipGrep;
cfg.ignorefile = PathBuf::from(".zettelsignore");
let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 7);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
}
#[test]
fn test_zettelsignore_native() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::Native;
cfg.ignorefile = PathBuf::from(".zettelsignore");
let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 7);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
}
#[test]
fn test_nonexsistent_ignorefile_grep() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::Grep;
cfg.ignorefile = PathBuf::from(".bar"); let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 12);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
assert!(index.files.contains_key(&PathBuf::from(".gitignore")));
assert!(index.files.contains_key(&PathBuf::from(".hiddendir/.hiddenfile2.txt")));
assert!(index.files.contains_key(&PathBuf::from(".hiddendir/a-file.txt")));
assert!(index.files.contains_key(&PathBuf::from(".hiddenfile.txt")));
assert!(index.files.contains_key(&PathBuf::from(".zettelsignore")));
}
#[test]
fn test_nonexsistent_ignorefile_ripgrep() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::RipGrep;
cfg.ignorefile = PathBuf::from(".bar"); let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 12);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
assert!(index.files.contains_key(&PathBuf::from(".gitignore")));
assert!(index.files.contains_key(&PathBuf::from(".hiddendir/.hiddenfile2.txt")));
assert!(index.files.contains_key(&PathBuf::from(".hiddendir/a-file.txt")));
assert!(index.files.contains_key(&PathBuf::from(".hiddenfile.txt")));
assert!(index.files.contains_key(&PathBuf::from(".zettelsignore")));
}
#[test]
fn test_nonexistent_ignorefile_native() {
let tmp_dir = tempdir().expect("Failed to setup temp dir");
let dir = tmp_dir.path();
generate_bare_examples(dir).expect("Failed to generate examples");
let rootdir = dir.join("examples/Zettelkasten");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = IndexingMethod::Native;
cfg.ignorefile = PathBuf::from(".bar"); let index = Index::new(&cfg)
.expect("Failed to create index.");
assert_eq!(index.files.len(), 12);
assert!(index.files.contains_key(&PathBuf::from("file1.md")));
assert!(index.files.contains_key(&PathBuf::from("file2.md")));
assert!(index.files.contains_key(&PathBuf::from("file3.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file4.md")));
assert!(index.files.contains_key(&PathBuf::from("subdir/file5.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/markdown-only.md")));
assert!(index.files.contains_key(&PathBuf::from("onlies/pure-yaml.yaml")));
assert!(index.files.contains_key(&PathBuf::from(".gitignore")));
assert!(index.files.contains_key(&PathBuf::from(".hiddendir/.hiddenfile2.txt")));
assert!(index.files.contains_key(&PathBuf::from(".hiddendir/a-file.txt")));
assert!(index.files.contains_key(&PathBuf::from(".hiddenfile.txt")));
assert!(index.files.contains_key(&PathBuf::from(".zettelsignore")));
}