use glass_easel_template_compiler::*;
#[test]
fn external_script() {
const SRC_A: &str = r#" {{ modA.a + modB.b }}"#;
const SRC_SCRIPT: &str = r#"(function(){return 0})()"#;
let mut group = TmplGroup::new();
group.add_tmpl("tmpl/a", SRC_A);
group.add_script("script/a", SRC_SCRIPT);
group.add_script("script/b", SRC_SCRIPT);
assert_eq!(
group
.script_dependencies("tmpl/a")
.unwrap()
.collect::>(),
vec!["script/a".to_string(), "script/b".to_string()],
);
}
#[test]
fn inline_script() {
const SRC_A: &str = r#"{{ modA.hi }}
exports.hi = 1 < 2 "#;
let mut group = TmplGroup::new();
group.add_tmpl("tmpl/a", SRC_A);
assert_eq!(group.script_dependencies("tmpl/a").unwrap().count(), 0);
assert_eq!(
group
.inline_script_module_names("tmpl/a")
.unwrap()
.collect::>(),
vec!["modA".to_string(), "modB".to_string()],
);
assert_eq!(
group.inline_script_content("tmpl/a", "modA").unwrap(),
" exports.hi = 1 < 2 "
);
assert_eq!(group.inline_script_content("tmpl/a", "modB").unwrap(), "");
}