pub fn load_contract(yaml_text: &str) -> Result<Contract, DeclarativeError>Expand description
Compile a declarative YAML contract (text) into a runtime Contract.
Examples found in repository?
examples/validate.rs (line 33)
32fn main() {
33 let contract = load_contract(CONTRACT).expect("the contract compiles");
34 let findings = validate(DOCUMENT, &contract, "decisions/zod.md");
35
36 for f in &findings {
37 let line = f.pos.map_or(0, |p| p.line);
38 println!("{}:{line} {:?} {}: {}", f.path, f.level, f.id, f.message);
39 }
40
41 // `status: done` is not in the enum and the Decision section is missing.
42 let errors = findings
43 .iter()
44 .filter(|f| f.level == FindingLevel::Error)
45 .count();
46 assert_eq!(errors, 2);
47}