use assert_cmd::Command;
use std::fs;
use std::path::Path;
macro_rules! md {
($s:expr) => {
$s.strip_prefix('\n').unwrap_or($s)
};
}
#[allow(unused_imports)]
pub(crate) use md;
#[allow(dead_code)]
pub fn hyalo() -> Command {
Command::cargo_bin("hyalo").unwrap()
}
#[allow(dead_code)]
pub fn hyalo_no_hints() -> Command {
let mut cmd = Command::cargo_bin("hyalo").unwrap();
cmd.arg("--no-hints");
cmd
}
pub fn write_md(dir: &Path, relative_path: &str, content: &str) {
let full = dir.join(relative_path);
if let Some(parent) = full.parent() {
fs::create_dir_all(parent).unwrap();
}
fs::write(full, content).unwrap();
}
#[allow(dead_code)]
pub fn write_tagged(dir: &Path, name: &str, tags: &[&str]) {
let tags_yaml = if tags.is_empty() {
"tags: []\n".to_owned()
} else {
let items = tags.iter().fold(String::new(), |mut s, t| {
use std::fmt::Write as _;
let _ = writeln!(s, " - {t}");
s
});
format!("tags:\n{items}")
};
write_md(
dir,
name,
&format!("---\ntitle: {name}\n{tags_yaml}---\n# Body\n"),
);
}
#[allow(dead_code)]
pub fn sample_frontmatter() -> &'static str {
md!(r#"
---
title: My Note
priority: 3
draft: true
created: "2026-03-20"
updated: "2026-03-20T14:30:00"
tags:
- rust
- cli
---
# Body
Some content here.
"#)
}