mod common;
use assert_cmd::prelude::*;
use common::dircat_cmd;
use predicates::prelude::*;
use std::fs;
use tempfile::tempdir;
#[test]
fn test_backticks_in_header() -> Result<(), Box<dyn std::error::Error>> {
let temp = tempdir()?;
fs::write(temp.path().join("file.txt"), "Content")?;
dircat_cmd()
.arg("-b") .current_dir(temp.path())
.assert()
.success()
.stdout(predicate::str::contains("## File: `file.txt`")) .stdout(predicate::str::contains("Content"));
temp.close()?;
Ok(())
}
#[test]
fn test_backticks_in_summary() -> Result<(), Box<dyn std::error::Error>> {
let temp = tempdir()?;
fs::write(temp.path().join("file1.txt"), "Content1")?;
fs::write(temp.path().join("file2 space.md"), "Content2")?;
dircat_cmd()
.arg("-b") .arg("-s") .current_dir(temp.path())
.assert()
.success()
.stdout(predicate::str::contains("## File: `file1.txt`")) .stdout(predicate::str::contains("## File: `file2 space.md`")) .stdout(predicate::str::contains("\n---\nProcessed Files: (2)\n"))
.stdout(predicate::str::contains("- `file1.txt`\n")) .stdout(predicate::str::contains("- `file2 space.md`\n"));
temp.close()?;
Ok(())
}
#[test]
fn test_backticks_in_dry_run() -> Result<(), Box<dyn std::error::Error>> {
let temp = tempdir()?;
fs::write(temp.path().join("file.txt"), "Content")?;
dircat_cmd()
.arg("-b") .arg("-D") .current_dir(temp.path())
.assert()
.success()
.stdout(predicate::str::contains(
"--- Dry Run: Files that would be processed ---",
))
.stdout(predicate::str::contains("- `file.txt`")) .stdout(predicate::str::contains("--- End Dry Run ---"));
temp.close()?;
Ok(())
}
#[test]
fn test_backticks_with_filename_spaces() -> Result<(), Box<dyn std::error::Error>> {
let temp = tempdir()?;
let file_with_space = "my file with spaces.txt";
fs::write(temp.path().join(file_with_space), "Space Content")?;
dircat_cmd()
.arg("-b") .arg("-s") .current_dir(temp.path())
.assert()
.success()
.stdout(predicate::str::contains(format!(
"## File: `{}`",
file_with_space
)))
.stdout(predicate::str::contains(format!(
"- `{}`\n",
file_with_space
)));
temp.close()?;
Ok(())
}