Skip to main content

code_moniker_check/scenario/
mod.rs

1//! Executable check scenarios: a Markdown document describing a file layout,
2//! an inline rules overlay, and the violations the layout is expected to
3//! produce. One document feeds an in-memory workspace the scan pipeline can run
4//! against; see `docs/check-scenarios.md` for the format contract.
5
6mod expect;
7mod parse;
8mod run;
9#[cfg(test)]
10mod tests;
11
12pub use expect::ExpectedViolation;
13pub use parse::ScenarioError;
14pub use run::ScenarioRun;
15
16#[derive(Clone, Debug, Default, Eq, PartialEq)]
17pub struct ScenarioMeta {
18	pub name: String,
19	pub title: String,
20	pub lang: String,
21	pub blurb: String,
22	pub summary: String,
23	pub published: bool,
24	pub default_rules: Option<bool>,
25}
26
27#[derive(Clone, Debug, Eq, PartialEq)]
28pub struct ScenarioFile {
29	pub path: String,
30	pub fence: String,
31	pub body: String,
32}
33
34#[derive(Clone, Debug, Eq, PartialEq)]
35pub struct UndemonstratedRule {
36	pub rule_id: String,
37	pub reason: String,
38}
39
40#[derive(Clone, Debug, Eq, PartialEq)]
41pub struct Scenario {
42	pub meta: ScenarioMeta,
43	pub rules: Option<String>,
44	pub files: Vec<ScenarioFile>,
45	pub expects: Vec<ExpectedViolation>,
46	pub undemonstrated: Vec<UndemonstratedRule>,
47	pub(crate) expect_span: Option<(usize, usize)>,
48}
49
50impl Scenario {
51	pub fn parse(document: &str) -> Result<Self, ScenarioError> {
52		parse::parse_document(document)
53	}
54
55	pub fn effective_default_rules(&self) -> bool {
56		self.meta.default_rules.unwrap_or(self.rules.is_none())
57	}
58}