extern crate libzettels;
extern crate tempfile;
use self::tempfile::tempdir;
use libzettels::{Config, Error, Index, IndexingMethod};
use libzettels::examples::*;
use std::fs::File;
use std::io::Write;
const FILE_BOILERPLATE: &str = "---
title: 'Edge cases of inline markdown link syntax'
keywords: []
followups: []
...
No matter which indexing method the user chooses, the following should not break things:
";
fn boilerplate(method: IndexingMethod, file_content: &str)
-> Result<Index, Error>{
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 dummy_file = File::create(rootdir.join("f(o)o.md"))
.expect("Failed to create dummy file with parentheses in filename.");
writeln!(dummy_file, "{}", "foo").expect("Failed to write to file");
let mut parentheses_file = File::create(
rootdir.join("test_file.md")
).expect("Failed to create temporary file.");
writeln!(parentheses_file, "{}", FILE_BOILERPLATE)
.expect("Failed to write to temporary file.");
writeln!(parentheses_file, "{}", file_content)
.expect("Failed to write to temporary file.");
let mut cfg = Config::new(rootdir.to_str().unwrap(), "foo");
cfg.indexingmethod = method;
Index::new(&cfg)
}
const PARENTHESES_FOLLOW: &str = "A [normal hyperlink](file1.md) (followed by parentheses) to a file";
#[test]
fn test_parentheses_follow_native() {
let index = boilerplate(IndexingMethod::Native, PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_follow_grep() {
let index = boilerplate(IndexingMethod::Grep, PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_follow_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep, PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
const PARENTHESES_IN_LINK_TEXT: &str = "A [hyperlink (with parentheses) in the link text](file1.md) to a file";
#[test]
fn test_parentheses_in_link_text_native() {
let index = boilerplate(IndexingMethod::Native, PARENTHESES_IN_LINK_TEXT);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_in_link_text_grep() {
let index = boilerplate(IndexingMethod::Grep, PARENTHESES_IN_LINK_TEXT);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_in_link_text_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep, PARENTHESES_IN_LINK_TEXT);
assert!(index.is_ok());
}
const PARENTHESES_IN_LINK_TEXT_AND_FOLLOW: &str = "A [hyperlink (with parentheses) in the link text](file1.md) (followed by parentheses) to a file";
#[test]
fn test_parentheses_in_link_text_and_follow_native() {
let index = boilerplate(IndexingMethod::Native, PARENTHESES_IN_LINK_TEXT_AND_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_in_link_text_and_follow_grep() {
let index = boilerplate(IndexingMethod::Grep, PARENTHESES_IN_LINK_TEXT_AND_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_in_link_text_and_follow_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep, PARENTHESES_IN_LINK_TEXT_AND_FOLLOW);
assert!(index.is_ok());
}
const HYPERLINK_INSIDE_PARENTHESES: &str = "A (link [inside](file1.md) parentheses) to a file";
#[test]
fn test_hyperlink_inside_parentheses_native() {
let index = boilerplate(IndexingMethod::Native,
HYPERLINK_INSIDE_PARENTHESES);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_inside_parentheses_grep() {
let index = boilerplate(IndexingMethod::Grep,
HYPERLINK_INSIDE_PARENTHESES);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_inside_parentheses_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep,
HYPERLINK_INSIDE_PARENTHESES);
assert!(index.is_ok());
}
const HYPERLINK_DIRECTLY_INSIDE_PARENTHESES: &str = "A ([link directly inside parentheses](file1.md)) to a file";
#[test]
fn test_hyperlink_directly_inside_parentheses_native() {
let index = boilerplate(IndexingMethod::Native,
HYPERLINK_DIRECTLY_INSIDE_PARENTHESES);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_directly_inside_parentheses_grep() {
let index = boilerplate(IndexingMethod::Grep,
HYPERLINK_DIRECTLY_INSIDE_PARENTHESES);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_directly_inside_parentheses_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep,
HYPERLINK_DIRECTLY_INSIDE_PARENTHESES);
assert!(index.is_ok());
}
const HYPERLINK_INSIDE_PARENTHESES_FOLLOW: &str = "A (link [inside](file1.md) parentheses) (followed by parentheses) to a file";
#[test]
fn test_hyperlink_inside_parentheses_follow_native() {
let index = boilerplate(IndexingMethod::Native,
HYPERLINK_INSIDE_PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_inside_parentheses_follow_grep() {
let index = boilerplate(IndexingMethod::Grep,
HYPERLINK_INSIDE_PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_inside_parentheses_follow_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep,
HYPERLINK_INSIDE_PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
const HYPERLINK_DIRECTLY_INSIDE_PARENTHESES_FOLLOW: &str = "A ([link directly inside parentheses](file1.md)) (followed by parentheses) to a file";
#[test]
fn test_hyperlink_directly_inside_parentheses_follow_native() {
let index = boilerplate(IndexingMethod::Native,
HYPERLINK_DIRECTLY_INSIDE_PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_directly_inside_parentheses_follow_grep() {
let index = boilerplate(IndexingMethod::Grep,
HYPERLINK_DIRECTLY_INSIDE_PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
#[test]
fn test_hyperlink_directly_inside_parentheses_follow_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep,
HYPERLINK_DIRECTLY_INSIDE_PARENTHESES_FOLLOW);
assert!(index.is_ok());
}
const TO_FILENAME_PARENTHESES: &str = " A [hyperlink](f(o)o.md) to a file with parentheses in the filename";
#[test]
fn test_to_filename_parentheses_native() {
let index = boilerplate(IndexingMethod::Native, TO_FILENAME_PARENTHESES);
assert!(index.is_ok());
}
#[test]
fn test_to_filename_parentheses_grep() {
let index = boilerplate(IndexingMethod::Grep, TO_FILENAME_PARENTHESES);
assert!(index.is_ok());
}
#[test]
fn test_to_filename_parentheses_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep, TO_FILENAME_PARENTHESES);
assert!(index.is_ok());
}
const PARENTHESES_FOLLOW_CLOSING: &str = "A [normal hyperlink](file1.md)) to a file followed by a single closing parenthesis";
#[test]
fn test_parentheses_follow_closing_native() {
let index = boilerplate(IndexingMethod::Native, PARENTHESES_FOLLOW_CLOSING);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_follow_closing_grep() {
let index = boilerplate(IndexingMethod::Grep, PARENTHESES_FOLLOW_CLOSING);
assert!(index.is_ok());
}
#[test]
fn test_parentheses_follow_closing_ripgrep() {
let index = boilerplate(IndexingMethod::RipGrep, PARENTHESES_FOLLOW_CLOSING);
assert!(index.is_ok());
}