This commit is contained in:
2025-04-05 09:56:10 +02:00
parent 78db13d738
commit 4be9445702
8 changed files with 185 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
mod dedent;
mod fix;
mod replace;
mod template;
pub use dedent::*;
pub use fix::*;
pub use replace::*;
pub use replace::*;
pub use template::*;

View File

@@ -210,9 +210,9 @@ mod tests {
#[test]
fn test_template_rendering() -> Result<(), Box<dyn std::error::Error>> {
// Create a temporary template file
let mut temp_file = NamedTempFile::new()?;
writeln!(temp_file, "Hello, {{ name }}! Welcome to {{ place }}.")?;
temp_file.flush()?;
let temp_file = NamedTempFile::new()?;
let template_content = "Hello, {{ name }}! Welcome to {{ place }}.\n";
fs::write(temp_file.path(), template_content)?;
// Create a template builder and add variables
let mut builder = TemplateBuilder::open(temp_file.path())?;
@@ -230,10 +230,9 @@ mod tests {
#[test]
fn test_template_with_multiple_vars() -> Result<(), Box<dyn std::error::Error>> {
// Create a temporary template file
let mut temp_file = NamedTempFile::new()?;
writeln!(temp_file, "{% if show_greeting %}Hello, {{ name }}!{% endif %}")?;
writeln!(temp_file, "{% for item in items %}{{ item }}{% if not loop.last %}, {% endif %}{% endfor %}")?;
temp_file.flush()?;
let temp_file = NamedTempFile::new()?;
let template_content = "{% if show_greeting %}Hello, {{ name }}!{% endif %}\n{% for item in items %}{{ item }}{% if not loop.last %}, {% endif %}{% endfor %}\n";
fs::write(temp_file.path(), template_content)?;
// Create a template builder and add variables
let mut builder = TemplateBuilder::open(temp_file.path())?;
@@ -273,13 +272,13 @@ mod tests {
Ok(())
}
#[test]
fn test_render_to_file() -> Result<(), Box<dyn std::error::Error>> {
// Create a temporary template file
let mut temp_file = NamedTempFile::new()?;
writeln!(temp_file, "{{ message }}")?;
temp_file.flush()?;
let temp_file = NamedTempFile::new()?;
let template_content = "{{ message }}\n";
fs::write(temp_file.path(), template_content)?;
// Create an output file
let output_file = NamedTempFile::new()?;