hornbeam/hornbeam_interpreter/tests/snapshots.rs

88 lines
1.7 KiB
Rust

use bevy_reflect::Reflect;
use hornbeam_interpreter::{localisation::DebugLocalisationSystem, LoadedTemplates, Params};
use insta::assert_snapshot;
#[derive(Reflect)]
struct SimpleTestStruct {
wombat: u64,
apple: u64,
banana: String,
carrot: String,
}
fn simple_test_struct() -> SimpleTestStruct {
SimpleTestStruct {
wombat: 42,
apple: 78,
banana: "banana!!!".to_owned(),
carrot: "mmm CARROT!".to_owned(),
}
}
fn simple_render(template: &str) -> String {
let mut templates = LoadedTemplates::new(DebugLocalisationSystem);
templates
.load_template_from_str("main", template, "main.hnb")
.expect("failed to load template");
let params = Params::default()
.set("sts", simple_test_struct())
.set("five", 5);
let prepared = templates.prepare("main", None, params, "en".to_owned());
prepared.render_to_string().unwrap()
}
#[test]
fn snapshot_001() {
assert_snapshot!(simple_render(
r#"
html
body
"this was a triumph :>"
br
raw "<u>making a note here, huge success</u>"
if $five == 5
"FIVE!!! $five"
br
if $five < 10
"five is less than ten!"
br
if $five > 5
"weird..."
"#
))
}
#[test]
fn snapshot_002() {
assert_snapshot!(simple_render(
r#"
@localiseMe{x=5}
br
"$five"
"#
))
}
#[test]
fn snapshot_003() {
assert_snapshot!(simple_render(
r#"
"unpadded: ${$sts.carrot}"
br
"padded to 15: ${$sts.carrot.leftpad(15, 'M')}"
br
"urlencoded: ${$sts.carrot.urlencode()}"
br
"length: ${$sts.carrot.len()}"
br
"split on A: "
for $part in $sts.carrot.split("A")
"($part)"
br
"#
))
}