add stub compile function and basic integration tests (#9)

This commit is contained in:
Josh Thomas 2024-10-13 18:26:49 -05:00 committed by GitHub
parent ab8daf12cb
commit dce0745ce4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 0 deletions

View file

@ -2,3 +2,13 @@ mod error;
mod lexer;
mod scanner;
mod token;
use std::error::Error;
pub fn compile(_template: &str) -> Result<String, Box<dyn Error>> {
todo!("Implement compilation process")
}
// re-export important types or functions from modules here, e.g.
// pub use lexer::Lexer;
// that should be part of the public API

45
tests/compile.rs Normal file
View file

@ -0,0 +1,45 @@
use django_template_ast::compile;
#[test]
#[should_panic]
fn test_empty_template() {
let result = compile("");
assert!(result.is_ok());
assert_eq!(result.unwrap(), "");
}
#[test]
#[should_panic]
fn test_simple_template() {
let result = compile("Hello, {{ name }}!");
assert!(result.is_ok());
// You'll need to adjust this expected output based on your actual implementation
assert_eq!(result.unwrap(), "Hello, {{ name }}!");
}
#[test]
#[should_panic]
fn test_invalid_template() {
let result = compile("{% invalid %}");
assert!(result.is_err());
}
#[test]
#[should_panic]
fn test_complex_template() {
let template = r#"
{% if user.is_authenticated %}
Hello, {{ user.name }}!
{% else %}
Please log in.
{% endif %}
"#;
let result = compile(template);
assert!(result.is_ok());
if let Ok(compiled) = result {
assert!(compiled.contains("Hello") && compiled.contains("Please log in"));
} else {
panic!("Compilation failed unexpectedly");
}
}