INNER CODE UNIT · Rust
missing_required_field_is_error
ShurikenTrade/shuriken-skills · src/frontmatter.rs:73
fn missing_required_field_is_error() {
let raw = "---\nname: foo\n---\n\nbody\n";
assert!(parse(raw).is_err());
}
#[test]
fn no_frontmatter_is_error() {
let raw = "just a body with no frontmatter";
assert!(parse(raw).is_err());
}
#[test]
fn body_lifetime_is_tied_to_input() {
const STATIC_INPUT: &str = "---\nname: foo\ndescription: bar\n---\n\nbody\n";
let parsed = parse(STATIC_INPUT).unwrap();
// This compile-time check locks in the invariant that body borrows
// from `raw`: if parse ever starts returning an owned String, this
// will fail to compile because you can't coerce String to &'static str.