#[cfg(test)]
mod tests {
use crate::test_helpers::*;
#[test]
fn test_bif_allow() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts >> en :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>en</div>");
}
#[test]
fn test_bif_allow_evaluate() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-{:;__test-nts:} >> {:;__test-nts:} :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>nts</div>");
}
#[test]
fn test_bif_allow_fails() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts >> notallow :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_negate() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:!allow; traversal >> is not traversal :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>is not traversal</div>");
}
#[test]
fn test_bif_allow_negate_fails() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:!allow; traversal >> ../istraversal :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_any() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; any >> something :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>something</div>");
}
#[test]
fn test_bif_allow_wildcard_empty() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-empty >> :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_wildcard_asterisk() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-asterisk >> en-nts :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>en-nts</div>");
}
#[test]
fn test_bif_allow_wildcard_asterisk_fails() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-asterisk >> not :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_wildcard_dot_1() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-dot >> ennts :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>ennts</div>");
}
#[test]
fn test_bif_allow_wildcard_dot_2() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-dot >> en-nts :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>en-nts</div>");
}
#[test]
fn test_bif_allow_wildcard_dot_fails() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-dot >> not :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_wildcard_question() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-question >> en-nts :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>en-nts</div>");
}
#[test]
fn test_bif_allow_wildcard_question_fails() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; _test-nts-question >> ennts :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_no_scope() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:+allow; _test-nts >> notallow :}</div>");
let result = template.render();
assert!(template.has_error());
assert_eq!(result, "<div></div>");
}
#[test]
fn test_bif_allow_flag_partial() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow;{:flg; partial :} _test-nts >> nts and more :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>nts and more</div>");
}
#[test]
fn test_bif_allow_flag_casein() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow;{:flg; casein :} _test-nts >> NTS :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>NTS</div>");
}
#[test]
fn test_bif_allow_flag_replace() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow;{:flg; replace :} _test-nts >> nts and more :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>nts</div>");
}
#[test]
fn test_bif_allow_multi_flags() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str("<div>{:allow; {:flg; casein replace :} _test-nts >> NTS :}</div>");
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>nts</div>");
}
#[test]
fn test_bif_allow_valid_flags() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template.set_src_str(
"<div>{:allow; {:flg; partial replace casein :} _test-nts >> nts and more :}</div>",
);
let result = template.render();
assert!(!template.has_error());
assert_eq!(result, "<div>nts</div>");
}
#[test]
fn test_bif_allow_invalid_flag() {
let mut template = match crate::Template::new() {
Ok(tpl) => tpl,
Err(error) => {
println!("Error creating Template: {}", error);
assert!(false);
return;
}
};
template.merge_schema_str(SCHEMA).unwrap();
template
.set_src_str("<div>{:allow; {:flg; invalid_flag :} _test-nts >> nts and more :}</div>");
let result = template.render();
assert!(template.has_error());
assert_eq!(result, "<div></div>");
}
}