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>
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use crate::*;
|
|
|
|
/// The `Engine` adapter: the wanderbooks implementation over `Store`, as
|
|
/// the bookspec runner drives any engine (`plan/served.md` P13 step 2).
|
|
impl Engine for Books<'_> {
|
|
fn load(&mut self, setup: &Setup) -> Result<(), Refusal> {
|
|
if setup != &self.ex.setup {
|
|
return Err(Refusal::new(
|
|
RuleId::new(Area::Ledger, 1),
|
|
"the setup handed over is not the example's",
|
|
));
|
|
}
|
|
self.setup();
|
|
Ok(())
|
|
}
|
|
|
|
fn apply(&mut self, event: &Event) -> Result<(), Refusal> {
|
|
let n = self.posted.len() + 1;
|
|
self.apply_event(n, event)
|
|
.map_err(|e| store_refusal_obj(&e))
|
|
}
|
|
|
|
fn change(&mut self, change: &ChangeSpec) -> Result<(), Refusal> {
|
|
self.try_change(change)
|
|
}
|
|
|
|
fn query(&self, q: &Query) -> Result<Value, Refusal> {
|
|
self.answer(q)
|
|
}
|
|
|
|
fn claims(&self) -> Claims {
|
|
Claims::new(
|
|
bookspec_checker::covered_rules()
|
|
.into_iter()
|
|
.map(|r| r.id.clone()),
|
|
)
|
|
}
|
|
}
|