You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These test codes for call func make strange error. Function 'tmpl_test1' can not pass, But function 'tmpl_test2' can pass.
The different between them:
In tmpl_test1, the function is stored in a map;
In tmpl_test2, the function is used straight.
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use gtmpl::{gtmpl_fn, template, Value};
use gtmpl_value::{self, FuncError, Function};
gtmpl_fn!(
fn shout(n: i64) -> Result<String, FuncError> {
let mut v = Vec::new();
for _ in 0..n {
v.push("wang".to_string());
}
Ok(v.join(","))
}
);
#[test]
fn tmpl_test1() {
let mut a: HashMap<String, Value> = HashMap::new();
a.insert(
"shout".to_string(),
Value::Function(Function { f: shout }),
);
let equal = template(r#"{{ call .shout 3 }}"#, a);
if equal.is_ok() {
assert_eq!(&equal.unwrap(), "wang,wang,wang");
} else {
assert_eq!(&equal.unwrap_err().to_string(), "wang,wang,wang");
}
}
#[test]
fn tmpl_test2() {
let equal: Result<String, gtmpl::TemplateError> = template(
r#"{{ call . 3 }}"#,
Value::Function(Function { f: shout }),
);
if equal.is_ok() {
assert_eq!(&equal.unwrap(), "wang,wang,wang");
} else {
assert_eq!(&equal.unwrap_err().to_string(), "wang,wang,wang");
}
}
}
The text was updated successfully, but these errors were encountered:
These test codes for call func make strange error. Function 'tmpl_test1' can not pass, But function 'tmpl_test2' can pass.
The different between them:
In tmpl_test1, the function is stored in a map;
In tmpl_test2, the function is used straight.
The text was updated successfully, but these errors were encountered: