requirements.examples.definition
Requirements index · View definition
Requirement
An mdBook chapter MAY define an example with an opening fence of at least three colons immediately followed by
{example} <name>and a closing colon-only fence of at least the opening length. The full name MUST use the same chapter-derived namespace and valid-name rules as{req}. The body MUST include all Markdown between the fences, excluding surrounding whitespace and the header option lines of, and MUST describe a concrete case with expected behavior. An example MUST contain at least one valid
{cite}or{test}reference to a requirement it illustrates;{cite}makes the requirement an input to the example’s assessment, and{test}makes the example an input to the requirement’s assessment, under. An example MAY use both. An example directive inside a fenced code block MUST remain literal.
Rationale
The reviewed tests cover each obligation of requirements.examples.definition, and their assertions enforce the expected outcomes. I did not request any implementation source.
- Fences and body (
src/evidence.rs#mod[tests]/fn[example_bodies_keep_nested_markdown_and_trim_outer_whitespace]):- It tries openings of 4 and 6 colons, each with a closing fence one colon longer.
- The body contains a nested
:::{note}block with a shorter 3-colon closing fence. That inner closing fence does not end the example, which shows a closing fence must be at least as long as the opening. - The body also contains a
{cite}, and the test asserts the body equals the original text exactly. This covers keeping all Markdown and trimming surrounding whitespace. - A
:::{example} literalinside a ```text code fence is asserted absent from the definitions, which covers the literal-in-code-block rule.
- Equal-length fences, name validity and namespace (
src/lib.rs#mod[tests]/fn[examples_are_distinct_definitions_and_tests_link_to_them]):- It nests an example with 3-colon fences inside a 4-colon
{req}. definition_blocksreturns exactly two blocks, sobad nameis rejected and the code-fenced example stays literal.- It asserts the rendered anchor
habeas-example-requirements.something.foo, which shows the namespace comes from the chapter (requirements.md).
- It nests an example with 3-colon fences inside a 4-colon
- Option lines (
src/lib.rs#mod[tests]/fn[anchor_options_are_metadata_not_body_text]andsrc/evidence.rs#mod[tests]/fn[anchored_files_must_be_completely_covered_and_resolvable]):- The first asserts an example’s
:test:option is excluded from its body, which becomes exactlyA case.. - The second asserts the example’s evidence text omits the option lines, with no “text changed” error.
- The first asserts an example’s
- At least one valid
{cite}or{test}(src/evidence.rs#mod[tests]/fn[examples_may_reference_their_requirement_with_cite_or_test]andfn[example_errors_include_duplicates_invalid_bodies_and_missing_tests]):{test}alone and{cite}alone are accepted.- Examples that use only
{impl}, a literal or escaped{cite}, an unknown target, or{term}are all rejected. - A cite of another example is rejected as well, since
nestedcitesrules.tested. - An empty body, a duplicate name and an unclosed fence produce errors.
- Using both roles (
src/evidence.rs#mod[tests]/fn[cited_example_with_a_test_and_matching_evidence_validates]): an example with both{cite}and{test}validates, and the test also checks the evidence-staleness paths. - Inputs (
src/authoring/inputs.rs#mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs]):- A
{cite}makes the requirement an input to the example’s assessment. - A
{test}from an example makes that example an input to the requirement’s assessment. - An example that only cites the requirement is not an input to the requirement.
- A
- Concrete case with expected behavior (
src/authoring/mod.rs#mod[tests]/fn[initial_prompt_carries_the_review_criteria]): the example prompt asserts the instruction “First check that it describes a concrete case with expected behavior; a missing concrete case or expected behavior is a gap.” This is how that obligation is enforced.
I found no requirement-violating behavior that these tests would accept. Chapter-derived namespace is tested only for a top-level chapter. The text says examples follow the same rules as {req}, which other requirements and tests cover, so I do not count this as a gap.
Inputs
Tests
Input 4: outline src/authoring/inputs.rs mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs]
- File:
src/authoring/inputs.rs - Selector:
mod[tests]/fn[only_edges_leaving_the_subject_contribute_inputs] - Kind:
fn src/authoring/inputs.rs:1298–1362
// {test}`requirements.references.authoring_inputs`
// {test}`requirements.references.roles`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.examples.definition`
#[test]
fn only_edges_leaving_the_subject_contribute_inputs() {
let root = project();
let declarations = format!(
":::{{req}} ready\nReady relies on {} and refines {}.\n:::\n\n:::{{req}} base\nBase MUST hold.\n:::\n\n:::{{req}} parent\nParent MUST hold.\n:::\n\n:::{{example}} citer\nA case relying on ready. {}\n:::\n\n:::{{example}} tester\nA ready case. {} {}\n:::\n",
role("cite", "requirements.base"),
role("impl", "requirements.parent"),
role("cite", "requirements.ready"),
role("cite", "requirements.base"),
role("test", "requirements.ready")
);
fs::write(root.path().join("md/requirements.md"), declarations).unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn run() {{}}\n// {}\nfn helper() {{}}\n// {}\nfn check() {{}}\n",
role("impl", "requirements.ready"),
role("cite", "requirements.ready"),
role("test", "requirements.ready")
),
)
.unwrap();
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let inputs = sources.mandatory_inputs();
let has_requirements =
|name: &str| inputs.iter().any(|input| input["requirements"] == name);
let has_item = |item: &str| inputs.iter().any(|input| input["item"] == item);
assert!(has_requirements("requirements.ready"));
assert!(has_requirements("requirements.base"), "{inputs:#?}");
assert!(has_requirements("requirements.tester"), "{inputs:#?}");
assert!(!has_item("fn[run]"), "{inputs:#?}");
assert!(has_item("fn[check]"), "{inputs:#?}");
assert!(!has_item("fn[helper]"), "{inputs:#?}");
assert!(!has_requirements("requirements.citer"), "{inputs:#?}");
assert!(!has_requirements("requirements.parent"), "{inputs:#?}");
let example = AssessmentSources::prepare(root.path(), "requirements.citer").unwrap();
assert!(
example
.mandatory_inputs()
.iter()
.any(|input| input["requirements"] == "requirements.ready"),
"{:#?}",
example.mandatory_inputs()
);
let parent = AssessmentSources::prepare(root.path(), "requirements.parent").unwrap();
let inputs = parent.mandatory_inputs();
assert!(
inputs
.iter()
.any(|input| input["requirements"] == "requirements.ready"),
"{inputs:#?}"
);
assert!(
!inputs
.iter()
.any(|input| input["requirements"] == "requirements.base"),
"{inputs:#?}"
);
}
Input 5: outline src/authoring/mod.rs mod[tests]/fn[initial_prompt_carries_the_review_criteria]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[initial_prompt_carries_the_review_criteria] - Kind:
fn src/authoring/mod.rs:2138–2210
// {test}`requirements.ci.review_criteria`
// {test}`requirements.authoring.requirement_task`
// {test}`requirements.authoring.testing_bar`
// {test}`requirements.authoring.example_task`
// {test}`requirements.authoring.judgment_rules`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.examples.evidence`
// {test}`requirements.examples.definition`
#[test]
fn initial_prompt_carries_the_review_criteria() {
let project = inputs::tests::project();
let sources = AssessmentSources::prepare(project.path(), "requirements.ready").unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
for criterion in [
"Subject: requirement requirements.ready\nJudge against: the subject's text.",
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
approved_text("requirement_task", 0),
approved_text("testing_bar", 0),
"Derive testable obligations and expected outcomes from each MUST, MUST NOT,",
"Testing criteria:",
"The project MUST be ready.",
] {
assert!(
prompt.contains(criterion),
"missing {criterion:?} in:\n{prompt}"
);
}
// The testing criteria follow the requirement task.
assert!(prompt.contains(&format!(
"{}\n{}",
approved_text("requirement_task", 0),
approved_text("testing_bar", 0)
)));
assert!(!prompt.contains(approved_text("example_task", 0)));
assert!(!prompt.contains("This subject is a distributed requirement."));
assert!(!prompt.contains(distributed_background()));
assert!(!prompt.contains("{{"), "{prompt}");
// An example's task replaces the requirement task.
let requirements = project.path().join("md/requirements.md");
let mut book = fs::read_to_string(&requirements).unwrap();
let cite = "{cite}`requirements.ready`";
book.push_str(&format!(
"\n:::{{example}} case\nA ready case. {cite}\n:::\n"
));
fs::write(&requirements, book).unwrap();
let sources = AssessmentSources::prepare(project.path(), "requirements.case").unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
assert!(
prompt.contains("Subject: example requirements.case"),
"{prompt}"
);
assert!(
prompt.contains(approved_text("example_task", 0)),
"{prompt}"
);
assert!(
prompt.contains("First check that it describes a concrete case\nwith expected behavior; a missing concrete case or expected behavior is a gap."),
"{prompt}"
);
assert!(
!prompt.contains(approved_text("requirement_task", 0)),
"{prompt}"
);
assert!(
!prompt.contains(approved_text("testing_bar", 0)),
"{prompt}"
);
assert!(!prompt.contains("Testing criteria:"), "{prompt}");
assert!(!prompt.contains("{{"), "{prompt}");
}
Input 6: outline src/evidence.rs mod[tests]/fn[example_bodies_keep_nested_markdown_and_trim_outer_whitespace]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[example_bodies_keep_nested_markdown_and_trim_outer_whitespace] - Kind:
fn src/evidence.rs:3476–3496
// {test}`requirements.examples.definition`
// {test}`requirements.ci.fence_lengths`
#[test]
fn example_bodies_keep_nested_markdown_and_trim_outer_whitespace() {
let temp = fixture();
let body = "# Concrete case\n\nGiven ready, it succeeds. {cite}`rules.ready`\n\n:::{note}\nNested explanation.\n:::\n\n```text\n:::{example} literal\n```\n\nThe expected result is success.";
for (opening, closing) in [("::::", ":::::"), ("::::::", ":::::::")] {
fs::write(
temp.path().join("md/rules.md"),
format!(
":::{{req}} ready\nReady.\n:::\n\n{opening}{{example}} case\n\n {body} \n\n{closing}\nText after the example.\n"
),
)
.unwrap();
let definitions = super::load_definitions(temp.path()).unwrap();
let example = &definitions["rules.case"];
assert_eq!(example.kind, crate::DefinitionKind::Example);
assert_eq!(example.text, body);
assert!(!definitions.contains_key("rules.literal"));
}
}
Input 7: outline src/evidence.rs mod[tests]/fn[cited_example_with_a_test_and_matching_evidence_validates]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[cited_example_with_a_test_and_matching_evidence_validates] - Kind:
fn src/evidence.rs:3498–3632
// {test}`requirements.examples.definition`
// {test}`requirements.examples.evidence`
// {test}`requirements.integration.report_api`
// {test}`requirements.ci.schema`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.ci.requirements_inputs`
// {test}`requirements.ci.orphans`
#[test]
fn cited_example_with_a_test_and_matching_evidence_validates() {
let temp = fixture();
let chapter = "# Rules\n\n:::{req} ready\nReady.\n:::\n\n:::{example} case\nGiven ready, it succeeds. {cite}`rules.ready` {test}`rules.ready`\n:::\n";
fs::write(temp.path().join("md/rules.md"), chapter).unwrap();
let test_source = "// {test}`rules.case`\n#[test]\nfn checks_case() { assert!(true); }\n";
fs::write(temp.path().join("src/main.rs"), test_source).unwrap();
fs::write(
temp.path().join("evidence/rules.ready.json"),
json!({
"requirement": "Ready.",
"determination": true,
"rationale": "The example cites this rule.",
"inputs": crate::inputs::outline_inputs_for_lines(temp.path(), "md/rules.md", 8, 8)
.unwrap()
})
.to_string(),
)
.unwrap();
let example_path = temp.path().join("evidence/rules.case.json");
fs::write(
&example_path,
json!({
"example": "Given ready, it succeeds. {cite}`rules.ready` {test}`rules.ready`",
"determination": true,
"rationale": "checks_case sets up ready and asserts the result.",
"inputs": [
outline(temp.path(), "src/main.rs", "fn[checks_case]"),
{
"requirements": "rules.*",
"matches": ["rules.case", "rules.ready"],
"text": [
chapter.lines().nth(6).unwrap(),
chapter.lines().nth(7).unwrap(),
chapter.lines().nth(8).unwrap(),
"",
chapter.lines().nth(2).unwrap(),
chapter.lines().nth(3).unwrap(),
chapter.lines().nth(4).unwrap()
]
}
]
})
.to_string(),
)
.unwrap();
let report = validate_repository(temp.path()).unwrap();
assert_eq!(report.requirements, 1);
assert_eq!(report.examples, 1);
assert_eq!(report.evidence_files, 2);
assert!(report.errors.is_empty(), "{:?}", report.errors);
let ready_path = temp.path().join("evidence/rules.ready.json");
let ready = fs::read_to_string(&ready_path).unwrap();
let mut missing: Value = serde_json::from_str(&ready).unwrap();
missing["inputs"] = json!([]);
fs::write(&ready_path, missing.to_string()).unwrap();
let errors = validate_repository(temp.path()).unwrap().errors;
assert!(
errors.iter().any(|error| error.contains("no input covers")
&& error.contains("{test}")
&& error.contains("rules.ready")
&& error.contains("md/rules.md:8")),
"{errors:?}"
);
fs::write(ready_path, ready).unwrap();
let old = fs::read_to_string(&example_path).unwrap();
let mut uncovered: serde_json::Value = serde_json::from_str(&old).unwrap();
uncovered["inputs"] = json!([]);
fs::write(&example_path, uncovered.to_string()).unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(errors.contains("no input covers"), "{errors}");
assert!(errors.contains("src/main.rs:1"), "{errors}");
fs::write(&example_path, &old).unwrap();
fs::write(
temp.path().join("src/main.rs"),
test_source.replace("assert!(true)", "assert!(false)"),
)
.unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(
errors.contains(
"outline input changed: src/main.rs fn[checks_case] (now lines 1-3) no longer has the recorded hash"
),
"{errors}"
);
fs::write(temp.path().join("src/main.rs"), test_source).unwrap();
fs::write(
temp.path().join("md/rules.md"),
format!("{chapter}\n:::{req} added\nAdded.\n:::\n", req = "{req}"),
)
.unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(
errors.contains(
"requirements glob \"rules.*\" matches changed; added [\"rules.added\"], removed []"
),
"{errors}"
);
let mut evidence: serde_json::Value = serde_json::from_str(&old).unwrap();
evidence["example"] = "Outdated.".into();
fs::write(&example_path, evidence.to_string()).unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(errors.contains("example text changed"), "{errors}");
assert!(errors.contains("- Outdated."), "{errors}");
let mut wrong_field: serde_json::Value = serde_json::from_str(&old).unwrap();
let example_text = wrong_field
.as_object_mut()
.unwrap()
.remove("example")
.unwrap();
wrong_field["requirement"] = example_text;
fs::write(&example_path, wrong_field.to_string()).unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(errors.contains("missing field \"example\""), "{errors}");
assert!(
errors.contains("unexpected field \"requirement\""),
"{errors}"
);
fs::remove_file(&example_path).unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(errors.contains("missing for example"), "{errors}");
}
Input 8: outline src/evidence.rs mod[tests]/fn[example_errors_include_duplicates_invalid_bodies_and_missing_tests]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[example_errors_include_duplicates_invalid_bodies_and_missing_tests] - Kind:
fn src/evidence.rs:3693–3724
// {test}`requirements.ci.definition_errors`
// {test}`requirements.examples.definition`
// {test}`requirements.examples.evidence`
#[test]
fn example_errors_include_duplicates_invalid_bodies_and_missing_tests() {
let temp = fixture();
let chapter = ":::{req} repeated\nReady.\n:::\n\n:::{req} repeated\nAgain.\n:::\n\n:::{example} repeated\nGiven ready. {cite}`rules.repeated`\n:::\n\n:::{example} case\nGiven ready. {cite}`rules.repeated`\n:::\n\n:::{example} case\nAgain. {cite}`rules.repeated`\n:::\n\n:::{example} empty\n \n:::\n\n:::{example} unclosed\nNo close.";
fs::write(temp.path().join("md/rules.md"), chapter).unwrap();
fs::write(
temp.path().join("evidence/rules.case.json"),
json!({
"example": "Given ready. {cite}`rules.repeated`",
"determination": true,
"rationale": "No test has been cited yet.",
"inputs": []
})
.to_string(),
)
.unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
for detail in [
"duplicate requirement rules.repeated; first declared at md/rules.md:1",
"duplicate example rules.repeated; first declared at md/rules.md:1",
"duplicate example rules.case; first declared at md/rules.md:13",
"example rules.empty has no text",
"example rules.empty must reference at least one requirement with {cite} or {test}",
"example rules.unclosed is missing a closing colon fence",
"example rules.case has a true determination but no {test} reference",
] {
assert!(errors.contains(detail), "missing {detail:?} in:\n{errors}");
}
}
Input 9: outline src/evidence.rs mod[tests]/fn[examples_may_reference_their_requirement_with_cite_or_test]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[examples_may_reference_their_requirement_with_cite_or_test] - Kind:
fn src/evidence.rs:3726–3758
// {test}`requirements.examples.definition`
// {test}`requirements.definitions.references`
#[test]
fn examples_may_reference_their_requirement_with_cite_or_test() {
let temp = fixture();
let chapter = ":::{req} ready\nReady.\n:::\n\n:::{example} tested\nGiven ready. {test}`rules.ready`\n:::\n\n:::{example} cited\nGiven ready. {cite}`rules.ready`\n:::\n\n:::{example} nested\nLike the tested case. {cite}`rules.tested`\n:::\n\n:::{example} implemented\nGiven ready. {impl}`rules.ready`\n:::\n\n:::{example} literal\nGiven ready. `{cite}`rules.ready`` and \\{cite}`rules.ready`\n:::\n\n:::{example} unknown\nGiven ready. {cite}`rules.absent`\n:::\n\n:::{example} termed\nGiven ready. {term}`rules.ready`\n:::\n";
fs::write(temp.path().join("md/rules.md"), chapter).unwrap();
let errors = validate_repository(temp.path()).unwrap().errors.join("\n");
assert!(
!errors.contains("example rules.tested must reference"),
"{errors}"
);
assert!(
!errors.contains("example rules.cited must reference"),
"{errors}"
);
assert!(
errors.contains(
"example rules.nested must reference at least one requirement with {cite} or {test}"
),
"{errors}"
);
// Only `{cite}` or `{test}` counts, and only as a valid reference; a
// `{term}` naming the requirement does not.
for name in ["implemented", "literal", "unknown", "termed"] {
assert!(
errors.contains(&format!(
"example rules.{name} must reference at least one requirement with {{cite}} or {{test}}"
)),
"{name}: {errors}"
);
}
}
Input 10: outline src/evidence.rs mod[tests]/fn[anchored_files_must_be_completely_covered_and_resolvable]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[anchored_files_must_be_completely_covered_and_resolvable] - Kind:
fn src/evidence.rs:3760–3851
// {test}`requirements.references.anchors`
// {test}`requirements.ci.requirement_text`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.ci.span`
// {test}`requirements.examples.definition`
#[test]
fn anchored_files_must_be_completely_covered_and_resolvable() {
let temp = fixture();
let root = temp.path();
fs::create_dir_all(root.join("skills")).unwrap();
fs::write(root.join("skills/ready.md"), "# Skill\nUse ready.\n").unwrap();
fs::write(
root.join("md/requirements.md"),
":::{req} ready\n:test: skills/ready.md\n:test: missing.sh\nReady MUST hold.\n:::\n\n:::{example} case\n:test: skills/ready.md\nA ready case. {cite}`requirements.ready`\n:::\n",
)
.unwrap();
// The root node is the whole file; its heading's section is not.
let skill = |item: &str| outline(root, "skills/ready.md", item);
let write = |name: &str, field: &str, text: &str, inputs: Value| {
fs::write(
root.join(format!("evidence/{name}.json")),
json!({
field: text,
"determination": true,
"rationale": "Checked.",
"inputs": inputs,
})
.to_string(),
)
.unwrap();
};
// The option lines are not part of the definition text.
write(
"requirements.ready",
"requirement",
"Ready MUST hold.",
json!([skill("section[Skill]")]),
);
write(
"requirements.case",
"example",
"A ready case. {cite}`requirements.ready`",
json!([skill("")]),
);
let errors = validate_repository(root).unwrap().errors.join("\n");
assert!(!errors.contains("text changed"), "{errors}");
assert!(
errors.contains("evidence/requirements.ready.json: no input selects skills/ready.md (lines 1-2) anchored by :test: on requirement requirements.ready"),
"{errors}"
);
assert!(
errors.contains("evidence/requirements.ready.json: :test: anchor missing.sh on requirement requirements.ready at md/requirements.md:1 does not resolve"),
"{errors}"
);
assert!(!errors.contains("requirements.case.json"), "{errors}");
fs::write(
root.join("md/requirements.md"),
":::{req} ready\n:test: skills/ready.md\nReady MUST hold.\n:::\n\n:::{example} case\n:test: skills/ready.md\nA ready case. {cite}`requirements.ready`\n:::\n",
)
.unwrap();
write(
"requirements.ready",
"requirement",
"Ready MUST hold.",
json!([skill("")]),
);
let report = validate_repository(root).unwrap();
assert!(report.errors.is_empty(), "{:?}", report.errors);
// Changing the anchored file makes the evidence stale.
fs::write(root.join("skills/ready.md"), "# Skill\nUse ready now.\n").unwrap();
let errors = validate_repository(root).unwrap().errors.join("\n");
assert!(
errors.contains("evidence/requirements.ready.json: inputs[0]: outline input changed: skills/ready.md <root> (now lines 1-2) no longer has the recorded hash"),
"{errors}"
);
fs::write(
root.join("habeas.toml"),
"version = 1\n[evidence]\ndisallow = ['skills/ready.md']\n",
)
.unwrap();
let errors = validate_repository(root).unwrap().errors;
assert!(
errors
.iter()
.any(|error| error.contains("anchor skills/ready.md")
&& error.contains("requirements.ready")
&& error.contains("disallow")),
"{errors:?}"
);
}
Input 11: outline src/lib.rs mod[tests]/fn[anchor_options_are_metadata_not_body_text]
- File:
src/lib.rs - Selector:
mod[tests]/fn[anchor_options_are_metadata_not_body_text] - Kind:
fn src/lib.rs:1006–1048
// {test}`requirements.references.anchors`
#[test]
// {test}`requirements.ci.span`
// {test}`requirements.examples.definition`
fn anchor_options_are_metadata_not_body_text() {
let source = "::::{req} ready\n:impl: skills/ready.md\n:test: tests/ready.sh\nReady.\n\n:::{example} case\n:test: tests/case.sh\nA case.\n:::\n::::\n\n:::{req} plain\nText :impl: inline.\n\n:test: later.md\n:::\n";
let blocks = definition_blocks(source);
assert_eq!(blocks.len(), 3);
let options = |index: usize| {
blocks[index]
.options
.iter()
.map(|option| (option.name.as_str(), option.value.as_str(), option.line))
.collect::<Vec<_>>()
};
assert_eq!(
options(0),
[
("impl", "skills/ready.md", 2),
("test", "tests/ready.sh", 3)
]
);
assert_eq!(options(1), [("test", "tests/case.sh", 7)]);
// Only lines immediately after the opening fence are options.
assert!(options(2).is_empty());
assert_eq!(
super::without_options(source, blocks[0].body_start..blocks[0].body_end, &blocks)
.trim(),
"Ready.\n\n:::{example} case\nA case.\n:::"
);
assert_eq!(
super::without_options(source, blocks[1].body_start..blocks[1].body_end, &blocks)
.trim(),
"A case."
);
let rendered = replace_definitions(source, "requirements", None, None);
assert!(!rendered.contains(":impl: skills"), "{rendered}");
assert!(!rendered.contains("skills/ready.md"), "{rendered}");
assert!(!rendered.contains("tests/case.sh"), "{rendered}");
assert!(rendered.contains("Text :impl: inline."), "{rendered}");
assert!(rendered.contains(":test: later.md"), "{rendered}");
}
Input 12: outline src/lib.rs mod[tests]/fn[examples_are_distinct_definitions_and_tests_link_to_them]
- File:
src/lib.rs - Selector:
mod[tests]/fn[examples_are_distinct_definitions_and_tests_link_to_them] - Kind:
fn src/lib.rs:1941–1995
// {test}`requirements.examples.definition`
// {test}`requirements.references.book_badges`
// {test}`requirements.ci.identifiers`
// {test}`requirements.examples.index`
#[test]
fn examples_are_distinct_definitions_and_tests_link_to_them() {
let source = "::::{req} ready\nReady.\n\n:::{example} something.foo\nGiven ready, it succeeds. {cite}`requirements.ready`\n:::\n::::\n\n:::{example} bad name\nInvalid.\n:::\n\n```text\n:::{example} hidden\nLiteral.\n:::\n```".to_owned();
let blocks = definition_blocks(&source);
assert_eq!(blocks.len(), 2);
assert_eq!(blocks[0].kind, DefinitionKind::Requirement);
assert_eq!(blocks[1].kind, DefinitionKind::Example);
let mut book = Book::new();
book.push_item(Chapter::new(
"Requirements",
source,
"requirements.md",
Vec::new(),
));
book.push_item(Chapter::new(
"Guide",
"{test}`requirements.something.foo`".to_owned(),
"guides/deep.md",
Vec::new(),
));
let root = book_root();
preprocess_book(&mut book, root.path()).unwrap();
// Generated detail pages are titled by full name.
let chapters = book
.chapters()
.filter(|chapter| !chapter.name.contains('.'))
.collect::<Vec<_>>();
assert!(
chapters[0]
.content
.contains("id=\"habeas-req-requirements.ready\"")
);
assert!(
chapters[0]
.content
.contains("id=\"habeas-example-requirements.something.foo\"")
);
assert!(
chapters[0]
.content
.contains("alt=\"example requirements.something.foo\"")
);
assert!(chapters[0].content.contains(":::{example} bad name"));
assert!(chapters[0].content.contains(":::{example} hidden"));
assert!(
chapters[1].content.contains(
"href=\"../requirements.html#habeas-example-requirements.something.foo\""
)
);
}
Referenced definitions
Input 2: requirements selection requirements.references.anchors
requirements.references.anchors:md/requirements/references.md:176–197
:::{req} anchors
A `{req}` declaration MAY list `:impl:` and `:test:` options, and an `{example}`
declaration MAY list `:test:` options, immediately after its opening fence and
before its body, one per option line, naming a project file path or
`path#selector` for one outline node under
{cite}`requirements.references.outline_selectors`. Each anchor MUST be an `{impl}` or `{test}` edge, under
{cite}`requirements.references.roles`, from the definition to the anchored file or
node, for files that cannot or should not carry a reference themselves.
Paths MUST follow the path rules in {cite}`requirements.ci.schema`. Option lines
MUST NOT form part of the definition's text for evidence comparison or for
requirements inputs, and MUST NOT render as body text.
For each `:test:` anchor, the harness MUST include the selected file or node's
source text in the initial model request under
{cite}`requirements.authoring.mandatory_inputs` and MUST record that selection
as an evidence input under {cite}`requirements.references.evidence_coverage`,
so changing that source makes the evidence stale.
A `:impl:` anchor alone MUST NOT require an input selecting its source. A path or selector that
does not resolve to a readable, permitted file or node MUST be a validation error naming the
definition and the path; authoring MUST report it before inference. Any other option line in a `{req}` or
`{example}` declaration MUST be a validation error.
:::
Input 3: requirements selection requirements.references.roles
requirements.references.roles:md/requirements/references.md:3–49
:::{req} roles
Project text files MAY use the `{impl}`, `{cite}`, and `{test}` roles with a backtick-delimited full requirement or example name, or with a built-in name under {cite}`requirements.references.builtin_definitions`, and MAY use the `{fixme}` role in fenced form. A reference MAY instead be written in fenced form, `:::{role} name` on one line, a body, and a closing fence, following the fence rules of {cite}`requirements.ci.span` and {cite}`requirements.ci.fence_lengths`; the fenced form is the same edge with attached commentary, and the inline form carries none. In a source comment, fence lines MUST be recognized after removing each line's comment delimiters within one comment run under {cite}`requirements.references.outline_comments`, and a fence that does not close within its comment run MUST be a validation error. Each reference is a directed edge between its source and the named definition. A source is a project source item or a requirement or example declaration. The roles MUST mean:
- `{cite}`: the source relies on, supports, or refers to the definition. It is an
edge from the source to the definition.
- `{impl}`: the source implements part of the definition: it makes a decision,
performs a check, produces an output, or handles a case that the definition
specifies. A requirement MAY implement part of another requirement by refining
one of its obligations. Calling code that implements a definition, or
producing a result a caller uses to meet it, MUST NOT by itself count as
implementing it. A check MUST count only if the definition states it, or the
source could not meet one of the definition's obligations without it; source
that checks it is consistent with a definition, such as recognizing a form the
definition specifies in order to decide whether to run other behavior, relies
on that definition and calls for `{cite}`. A requirement stating a convention
for every output of a kind, such as every validation error, is implemented by
the source that carries out the convention as a whole, such as the step that
collects and reports those outputs.
- `{test}`: the source is designed to verify behavior the definition specifies:
a test through its scenario and the assertions about that scenario's outcome,
or a named example through the concrete case it describes.
- `{fixme}`: the source acknowledges a known gap in fulfilling the definition. It
MUST use the fenced form, and its body MUST describe the gap. The body MAY
begin with option lines naming issues that track the gap, one per line, in the
form `:github: <owner>/<repo>#<number>`, such as
`:github: rust-lang/rust#123`. `github` MUST be the only recognized option.
A named `{fixme}` MAY appear only in sources outside the book. Validation MUST report
any other option line, a `:github:` value not in that form, an inline
`{fixme}`, a `{fixme}` in a requirement or example declaration, and a
`{fixme}` whose body, without option lines and comment delimiters, is empty.
An unnamed `{fixme}`, a fence of `:::{fixme}` with no name, MAY appear in any
project text, including a requirement or example body, to tie that place to
the issues it names. It MUST have at least one `:github:` option line and MAY
have a description; it is not a reference edge, acknowledges no gap, needs no
coverage, and does not count as a reference for Rust item coverage. Its
issues are checked under {cite}`requirements.cli.fixme_issues`.
`{impl}`, `{test}`, and `{fixme}` are edges from the definition to the source.
Only requirements and examples are assessed; code is reviewed as part of the
definitions it implements or tests.
```text
{impl}`requirements.references.roles`
{cite}`requirements.references.roles`
{test}`requirements.references.roles`
```
:::
Other sources
Input 1: requirements selection requirements.examples.definition
requirements.examples.definition:md/requirements/examples.md:3–5
:::{req} definition
An mdBook chapter MAY define an example with an opening fence of at least three colons immediately followed by `{example} <name>` and a closing colon-only fence of at least the opening length. The full name MUST use the same chapter-derived namespace and valid-name rules as `{req}`. The body MUST include all Markdown between the fences, excluding surrounding whitespace and the header option lines of {cite}`requirements.references.anchors`, and MUST describe a concrete case with expected behavior. An example MUST contain at least one valid `{cite}` or `{test}` reference to a requirement it illustrates; `{cite}` makes the requirement an input to the example's assessment, and `{test}` makes the example an input to the requirement's assessment, under {cite}`requirements.references.roles`. An example MAY use both. An example directive inside a fenced code block MUST remain literal.
:::