feat: add new dependencies and integration tests for markdown and text formats
This commit is contained in:
4
tests/fixtures/example.rs
vendored
Normal file
4
tests/fixtures/example.rs
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
// This is a sample Rust file for testing purposes.
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
1
tests/fixtures/example.txt
vendored
Normal file
1
tests/fixtures/example.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Example text file content
|
79
tests/integration_tests.rs
Normal file
79
tests/integration_tests.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use codebase_to_prompt::{Config, Format, run};
|
||||
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: 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,
|
||||
};
|
||||
|
||||
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: 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,
|
||||
};
|
||||
|
||||
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: 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,
|
||||
};
|
||||
|
||||
let result = run(config);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let output_file_name = output_file.file_name().unwrap().to_str().unwrap();
|
||||
assert!(output_file_name.contains("output"));
|
||||
assert!(output_file_name.len() > "output".len());
|
||||
}
|
Reference in New Issue
Block a user