use super::*;
#[test]
fn test_check_condition() {
let mut kind = RuleType::Suffix;
let mut rule = AfxRulePattern::default();
rule.set_pattern("[^aeiou]y", kind).unwrap();
assert!(rule.check_condition("xxxy"));
assert!(!rule.check_condition("xxxay"));
assert!(!rule.check_condition("xxxyxx"));
kind = RuleType::Prefix;
rule.set_pattern("y[^aeiou]", kind).unwrap();
assert!(rule.check_condition("yxxx"));
assert!(!rule.check_condition("yaxxx"));
assert!(!rule.check_condition("xxxyxxx"));
kind = RuleType::Suffix;
rule.set_pattern("[sxzh]", kind).unwrap();
assert!(rule.check_condition("access"));
assert!(rule.check_condition("abyss"));
assert!(!rule.check_condition("accomplishment"));
assert!(rule.check_condition("mmms"));
assert!(!rule.check_condition("mmsmm"));
rule.set_pattern(".", kind).unwrap();
assert!(rule.check_condition("xxx"));
}
#[test]
fn test_apply_pattern() {
let mut kind = RuleType::Suffix;
let mut rule = AfxRulePattern::new("zzz", Some("y"));
rule.set_pattern("[^aeiou]y", kind).unwrap();
assert_eq!(rule.apply_pattern("xxxy", kind), Some("xxxzzz".to_owned()));
kind = RuleType::Prefix;
rule.set_pattern("y[^aeiou]", kind).unwrap();
assert_eq!(rule.apply_pattern("yxxx", kind), Some("zzzxxx".to_owned()));
kind = RuleType::Suffix;
rule.set_pattern(".", kind).unwrap();
assert_eq!(rule.apply_pattern("xxx", kind), Some("xxxzzz".to_owned()));
}