requirements.references.definition_glob_cases
Requirements index · View definition
Example
Given a requirement
foo.a.barand a named examplefoo.a.b.bar,foo.*.barmatches both, in full-name order:foo.a.b.barbeforefoo.a.bar. A requirements input stores both full names and their complete raw fenced declarations. Adding another matching definition invalidates the existing input.![]()
Rationale
The example requirements.references.definition_glob_cases is a concrete case with stated outcomes. The case is a requirement foo.a.bar, a named example foo.a.b.bar, and the glob foo.*.bar. The outcomes are that both definitions match, that they come in full-name order with the example first, that the input stores both full names and complete raw fenced declarations, and that adding another matching definition invalidates the input.
Two tests reference the example, and together they cover every outcome:
src/evidence.rs#mod[tests]/fn[requirements_inputs_track_matched_declarations_in_full_name_order]builds exactly this scenario.- It writes
a.baras a req anda.b.baras an example inmd/foo.md, and it stores a requirements input with globfoo.*.bar. - The input’s
matchesare["foo.a.b.bar","foo.a.bar"], so a wrong match set or wrong order would produce errors. Itstextis the example’s full declaration, then a blank line, then the requirement’s full declaration. The first assertion requires no errors, so it checks matching of both definitions across dots, the order with the example first, and the complete raw fenced text. - It also checks that moving the declarations does not invalidate the input.
- Adding
z.bar(foo.z.bar) produces the error “matches changed; added ["foo.z.bar"]”. This covers the “adding another matching definition invalidates the input” outcome. - Removing the example and renaming the requirement produce the corresponding errors.
- Changing a declaration’s text, a glob that matches nothing, an empty glob and an invalid glob are also checked.
- It writes
src/definition_glob.rs#mod[tests]/fn[wildcard_crosses_dot_segments_and_matches_the_whole_name]checks the matching rule directly.*crosses dots (foo.*.barmatches bothfoo.x.barandfoo.x.y.bar), matching is anchored to the whole name, and an empty glob is invalid.
I found no gap in the scenario coverage or in the assertions’ expected results.
Inputs
Tests
Input 4: outline src/definition_glob.rs mod[tests]/fn[wildcard_crosses_dot_segments_and_matches_the_whole_name]
- File:
src/definition_glob.rs - Selector:
mod[tests]/fn[wildcard_crosses_dot_segments_and_matches_the_whole_name] - Kind:
fn src/definition_glob.rs:40–57
// {test}`requirements.references.definition_globs`
// {test}`requirements.references.definition_glob_cases`
#[test]
fn wildcard_crosses_dot_segments_and_matches_the_whole_name() {
assert!(validate("foo.*.bar").is_ok());
assert!(matches("foo.*.bar", "foo.x.bar"));
assert!(matches("foo.*.bar", "foo.x.y.bar"));
assert!(!matches("foo.*.bar", "prefix.foo.x.bar"));
assert!(!matches("foo.*.bar", "foo.x.bar.suffix"));
assert!(!matches("foo.bar", "fooxbar"));
assert!(matches("foo_bar-baz", "foo_bar-baz"));
assert!(!matches("foo_bar-baz", "fooXbar-baz"));
assert!(!matches("foo_bar-baz", "foo_barXbaz"));
assert!(!matches("foo.bar.*", "foo.bar"));
assert!(matches("foo.bar.*", "foo.bar.x.y"));
assert!(validate("").is_err());
assert!(validate("foo[bar]").is_err());
}
Input 5: outline src/evidence.rs mod[tests]/fn[requirements_inputs_track_matched_declarations_in_full_name_order]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[requirements_inputs_track_matched_declarations_in_full_name_order] - Kind:
fn src/evidence.rs:2857–2975
// {test}`requirements.ci.requirements_inputs`
// {test}`requirements.references.definition_glob_cases`
// {test}`requirements.references.definition_globs`
#[test]
fn requirements_inputs_track_matched_declarations_in_full_name_order() {
let temp = fixture();
let bar = ":::{req} a.bar\nBar.\n:::\n";
let nested = ":::{example} a.b.bar\nNested. {cite}`foo.a.bar`\n:::\n";
let other = ":::{req} other\nOther.\n:::\n";
let write = |declarations: &[&str]| {
fs::write(
temp.path().join("md/foo.md"),
format!("# Foo\n\n{}", declarations.join("\n")),
)
.unwrap();
};
let lines = |declaration: &str| declaration.lines().map(str::to_owned).collect::<Vec<_>>();
let mut text = lines(nested);
text.push(String::new());
text.extend(lines(bar));
let record = |glob: &str| {
json!({
"requirement": "Other.",
"determination": true,
"rationale": "Both matches were examined.",
"inputs": [{
"requirements": glob,
"matches": ["foo.a.b.bar", "foo.a.bar"],
"text": text,
}]
})
.to_string()
};
fs::write(
temp.path().join("evidence/foo.other.json"),
record("foo.*.bar"),
)
.unwrap();
let errors = || {
validate_repository(temp.path())
.unwrap()
.errors
.into_iter()
.filter(|error| error.starts_with("evidence/foo.other.json"))
.collect::<Vec<_>>()
};
// `*` crosses dots, the example sorts before the requirement by full
// name, and the stored text is both complete fenced declarations.
write(&[bar, nested, other]);
assert!(errors().is_empty(), "{:?}", errors());
// Moving unchanged declarations does not invalidate the input.
write(&[other, "Some prose.\n", nested, "More prose.\n", bar]);
assert!(errors().is_empty(), "{:?}", errors());
write(&[&bar.replace("Bar.", "Changed."), nested, other]);
let changed = errors().join("\n");
assert!(
changed.contains(
"inputs[0]: input text changed for Requirements { requirements: \"foo.*.bar\" }; changed definitions [\"foo.a.bar\"]\n- Bar.\n+ Changed."
),
"{changed}"
);
let added = ":::{req} z.bar\nAdded.\n:::\n";
write(&[bar, nested, other, added]);
assert!(
errors().join("\n").contains(
"inputs[0]: requirements glob \"foo.*.bar\" matches changed; added [\"foo.z.bar\"], removed []"
),
"{:?}",
errors()
);
write(&[bar, other]);
assert!(
errors().join("\n").contains(
"requirements glob \"foo.*.bar\" matches changed; added [], removed [\"foo.a.b.bar\"]"
),
"{:?}",
errors()
);
write(&[&bar.replace("a.bar", "c.bar"), nested, other]);
assert!(
errors().join("\n").contains(
"requirements glob \"foo.*.bar\" matches changed; added [\"foo.c.bar\"], removed [\"foo.a.bar\"]"
),
"{:?}",
errors()
);
write(&[bar, nested, other]);
fs::write(
temp.path().join("evidence/foo.other.json"),
record("foo.*.none"),
)
.unwrap();
assert_eq!(
errors(),
[
"evidence/foo.other.json: inputs[0]: requirements glob \"foo.*.none\" matches no requirement or example"
]
);
// A selection that is not a valid definition glob is rejected.
for (glob, problem) in [
("foo.[a].bar", "unsupported character '['"),
("", "definition glob must not be empty"),
] {
fs::write(temp.path().join("evidence/foo.other.json"), record(glob)).unwrap();
let found = errors();
assert!(
found.len() == 1
&& found[0].contains("inputs[0]")
&& found[0].contains(&format!("requirements glob {glob:?}"))
&& found[0].contains(problem),
"{glob:?}: {found:?}"
);
}
}
Referenced definitions
Input 2: requirements selection requirements.references.definition_globs
requirements.references.definition_globs:md/requirements/references.md:331–333
:::{req} definition_globs
A definition glob MUST match a complete full name. `*` MUST match zero or more characters, including dots; all other valid name characters MUST match literally. An empty glob MUST be invalid. Every definition selection MUST use this matching rule, including requirements evidence inputs, CLI definition filters, and the authoring `references` tool, and MUST match against both requirements and named examples.
:::
Input 3: requirements selection requirements.ci.requirements_inputs
requirements.ci.requirements_inputs:md/requirements/ci.md:185–187
:::{req} requirements_inputs
For a requirements input, `requirements` MUST be a {term}`requirements.references.definition_selection`, and Habeas MUST match it against all defined requirements and named examples. It MUST recompute the matches during validation, sort their full names, and compare them with `matches`. It MUST take each match's complete raw fenced declaration, including its opening and closing lines, concatenate those declarations in full-name order with one blank line between them, and compare the resulting raw lines with `text`. It MUST retain every match's current source file and inclusive line range for display and reference coverage. A selection matching no definitions MUST be invalid. Adding, removing, renaming, or changing a matched definition MUST invalidate the stored input; moving an unchanged declaration within the book MUST NOT. Errors MUST identify the selection and affected definitions when available.
:::
Input 6: definition requirements.references.definition_selection
requirements.references.definition_selection:md/requirements/references.md:335–342
:::{definition} definition_selection
:phrase: definition selection
A full requirement or example name, or a definition glob, identifying the
requirements and named examples it matches under
{cite}`requirements.references.definition_globs`. A name without `*` selects
exactly that definition.
:::
Other sources
Input 1: requirements selection requirements.references.definition_glob_cases
requirements.references.definition_glob_cases:md/requirements/references.md:465–467
:::{example} definition_glob_cases
Given a requirement `foo.a.bar` and a named example `foo.a.b.bar`, `foo.*.bar` matches both, in full-name order: `foo.a.b.bar` before `foo.a.bar`. A requirements input stores both full names and their complete raw fenced declarations. Adding another matching definition invalidates the existing input. {cite}`requirements.references.definition_globs` {cite}`requirements.ci.requirements_inputs`
:::