The bookspec adapter was one 4,647-line test file, and every later unit that adds a query or an event touches it. Split it by its own sections, with no behaviour change: `main` keeps the crate doc, the shared imports and the module list; `common` holds the shared vocabulary (dates, refusals, exact decimals, figure formatting); `books` the example's books and setup; `events` the application of each event; `queries/` the answers and checks per query family (statements, parties, tax, assets, formats, commands, dates); `engine` the `Engine` impl; `check` and `run` the drivers; and `examples`, `loader_tests`, `sources` and `rules_md` the tests by area. Every `#[test]` keeps its function name (52 tests, same names), and Cargo still builds one test target named `bookspec`. Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use crate::*;
|
|
|
|
/// The books an example sets up, with every event and change applied and
|
|
/// nothing checked.
|
|
pub(crate) fn load(ex: &Example) -> Books<'_> {
|
|
let mut b = Books::new(ex);
|
|
for (i, e) in ex.events.iter().enumerate() {
|
|
b.apply(i + 1, e);
|
|
for c in ex.changes.iter().filter(|c| c.after == i + 1) {
|
|
b.change(c);
|
|
}
|
|
}
|
|
b
|
|
}
|
|
|
|
/// Load an example and check every expectation: each one with `after = N`
|
|
/// on the books after event N (before the changes made after it), the
|
|
/// rest after the last event and every change. Gives each query checked,
|
|
/// with the test of another crate that checks its values, if any.
|
|
pub(crate) fn run(ex: &Example) -> Vec<(String, Option<&'static str>)> {
|
|
let afters = ex
|
|
.expect
|
|
.iter()
|
|
.map(|x| x.after)
|
|
.chain(ex.changes.iter().map(|c| Some(c.after)));
|
|
for after in afters {
|
|
assert!(
|
|
after.is_none_or(|n| n >= 1 && n <= ex.events.len()),
|
|
"{}: after = {after:?}: events count from 1, to {}",
|
|
ex.id,
|
|
ex.events.len()
|
|
);
|
|
}
|
|
let mut b = Books::new(ex);
|
|
let mut out = Vec::new();
|
|
for (i, e) in ex.events.iter().enumerate() {
|
|
b.apply(i + 1, e);
|
|
for x in ex.expect.iter().filter(|x| x.after == Some(i + 1)) {
|
|
out.push((x.query.clone(), check(&b, x)));
|
|
}
|
|
for c in ex.changes.iter().filter(|c| c.after == i + 1) {
|
|
b.change(c);
|
|
}
|
|
}
|
|
for x in ex.expect.iter().filter(|x| x.after.is_none()) {
|
|
out.push((x.query.clone(), check(&b, x)));
|
|
}
|
|
// What the books kept replays to the books (the journal, the live
|
|
// books and their projection agree).
|
|
b.store
|
|
.verify()
|
|
.unwrap_or_else(|e| panic!("{}: the books replay as kept: {e}", ex.id));
|
|
out
|
|
}
|