mirror of
https://github.com/joshuadavidthomas/django-template-ast.git
synced 2025-07-07 19:35:32 +00:00
add stub compile function and basic integration tests (#9)
This commit is contained in:
parent
ab8daf12cb
commit
dce0745ce4
2 changed files with 55 additions and 0 deletions
10
src/lib.rs
10
src/lib.rs
|
@ -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
45
tests/compile.rs
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue