Skip to content

Commit

Permalink
test: Add test for rustembed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Dec 28, 2021
1 parent 34fb76d commit 62ebdb0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/embed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[macro_use]
extern crate serde_json;

use handlebars::Handlebars;

#[test]
#[cfg(feature = "rust-embed")]
fn test_embed() {
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "tests/templates/"]
#[include = "*.hbs"]
struct Templates;

let mut hbs = Handlebars::new();
hbs.register_embed_templates::<Templates>().unwrap();

assert_eq!(1, hbs.get_templates().len());

let data = json!({
"name": "Andy"
});

assert_eq!(hbs.render("hello.hbs", &data).unwrap(), "Hello, Andy\n");
}
1 change: 1 addition & 0 deletions tests/templates/hello.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, {{name}}

0 comments on commit 62ebdb0

Please sign in to comment.