Files
codebase-to-prompt/tests/integration_tests.rs
Gabriel Kaszewski f260715334
Some checks failed
Continuous Integration / Build and Test on ubuntu-latest (push) Failing after 40s
update
2026-03-14 18:22:19 +01:00

89 lines
2.5 KiB
Rust

use codebase_to_prompt::{run, Config, Format};
use std::fs;
use std::path::PathBuf;
#[test]
fn test_run_with_markdown_format() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join("output.md");
let config = Config {
directory: vec![PathBuf::from("tests/fixtures")],
output: Some(output_file.clone()),
include: vec!["rs".to_string()],
exclude: vec![],
format: Format::Markdown,
append_date: false,
append_git_hash: false,
line_numbers: false,
ignore_hidden: true,
respect_gitignore: true,
relative_path: true,
};
let result = run(config);
assert!(result.is_ok());
let output_content = fs::read_to_string(output_file).unwrap();
assert!(output_content.contains("### `example.rs`"));
}
#[test]
fn test_run_with_text_format() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join("output.txt");
let config = Config {
directory: vec![PathBuf::from("tests/fixtures")],
output: Some(output_file.clone()),
include: vec!["txt".to_string()],
exclude: vec![],
format: Format::Text,
append_date: false,
append_git_hash: false,
line_numbers: true,
ignore_hidden: true,
respect_gitignore: true,
relative_path: false,
};
let result = run(config);
assert!(result.is_ok());
let output_content = fs::read_to_string(output_file).unwrap();
assert!(output_content.contains("1 | Example text file content"));
}
#[test]
fn test_run_with_git_hash_append() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join("output.txt");
let config = Config {
directory: vec![PathBuf::from("tests/fixtures")],
output: Some(output_file.clone()),
include: vec!["txt".to_string()],
exclude: vec![],
format: Format::Text,
append_date: false,
append_git_hash: true,
line_numbers: false,
ignore_hidden: true,
respect_gitignore: true,
relative_path: false,
};
let result = run(config);
assert!(result.is_ok());
let hashed_file = fs::read_dir(temp_dir.path())
.unwrap()
.filter_map(|e| e.ok())
.find(|e| {
let name = e.file_name();
let name = name.to_string_lossy();
name.starts_with("output_") && name.ends_with(".txt")
});
assert!(hashed_file.is_some(), "expected output file with git hash suffix");
}