use fig::Value;
use flower_core::schema::Constraint;
use flower_core::{
Consequence, FieldRule, FieldType, PathPat, Presentation, Severity, Term, Tint,
guards_without_terms,
};
#[test]
fn an_embedder_declares_and_reads_consequences_through_flower_alone() {
let rule: FieldRule = FieldRule::new(PathPat::key("recycle_bin"))
.ty(FieldType::Bool)
.present(Presentation::default().title("Recoverable delete"))
.on_change(Consequence::always("Reopens the vault."))
.on_change(
Consequence::when(false, "Deleting stops being recoverable.")
.severity(Severity::ConfirmExplicitly),
);
let both = rule.consequences_of(&Value::Bool(false));
assert_eq!(both.len(), 2);
assert_eq!(
rule.severity_of(&Value::Bool(false)),
Some(Severity::ConfirmExplicitly)
);
assert_eq!(rule.consequences_of(&Value::Bool(true)).len(), 1);
assert_eq!(rule.severity_of(&Value::Bool(true)), Some(Severity::Notice));
}
#[test]
fn the_guard_lint_is_reachable_too() {
let consequences = vec![Consequence::when("of", "typo for `off`")];
let terms = [Term::value("off"), Term::value("manual")];
assert_eq!(guards_without_terms(&consequences, &terms), vec!["of"]);
}
#[test]
fn the_tint_vocabulary_can_be_enumerated_through_flower() {
assert!(Tint::ALL.contains(&Tint::Danger));
}
#[test]
fn a_rule_with_no_declared_cost_reports_none() {
let rule: FieldRule = FieldRule::new(PathPat::key("title")).ty(FieldType::Str);
assert!(
rule.consequences_of(&Value::Str("anything".into()))
.is_empty()
);
assert_eq!(rule.severity_of(&Value::Str("anything".into())), None);
let _ = Constraint::Enum {
values: vec![],
closed: false,
};
}