The engine has always dropped hyphens too (plan P4b S4, the owner: "(vendor, normalized vendor_ref) (lower-case, spaces and hyphens removed)", pinned by duplicate_vendor_ref_refused_unless_a_reason_is_given); bookspec's record lost the hyphens in transcription and is corrected, so there is no divergence to note. PICKS and the claims file name the option ignore-case-spaces-and-hyphens, "spaces" being any whitespace, and the example ids follow the record's rename. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
137 lines
5.3 KiB
Rust
137 lines
5.3 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 {
|
|
let mut claims = Claims::new(
|
|
bookspec_checker::covered_rules()
|
|
.into_iter()
|
|
.map(|r| r.id.clone()),
|
|
);
|
|
for &(area, n, option) in PICKS {
|
|
claims = claims.with_choice(RuleId::new(area, n), option);
|
|
}
|
|
claims
|
|
}
|
|
}
|
|
|
|
/// Why wanderbooks does not run `ex`: it is an example for an option of a
|
|
/// CHOICE rule (`under`) that wanderbooks did not pick (`PICKS`). The
|
|
/// runner skips such an example for the same reason; the loader tests do
|
|
/// it with this.
|
|
pub(crate) fn unpicked_option(ex: &Example) -> Option<String> {
|
|
ex.under.iter().find_map(|u| {
|
|
let rule = RuleId::parse(&u.rule).ok()?;
|
|
let &(_, _, pick) = PICKS
|
|
.iter()
|
|
.find(|&&(area, n, _)| RuleId::new(area, n) == rule)?;
|
|
(pick != u.option).then(|| {
|
|
format!(
|
|
"for {} under {}; wanderbooks picks {pick}",
|
|
u.rule, u.option
|
|
)
|
|
})
|
|
})
|
|
}
|
|
|
|
/// The option wanderbooks picks for each CHOICE record split out of an
|
|
/// embedded choice (P14 unit S-C7); each is recorded in
|
|
/// `docs/spec/claims/<area>.md` as `**Pick (BS-<area>-<n>):**`.
|
|
pub(crate) const PICKS: &[(Area, u32, &str)] = &[
|
|
(Area::Entry, 6, "check-when-line-added"),
|
|
(Area::Entry, 7, "refuse-rather-than-crash"),
|
|
(Area::Entry, 8, "bounds-bind-commands-never-replay"),
|
|
(Area::Ledger, 6, "reversible-once"),
|
|
(Area::Ledger, 9, "facts-in-the-books"),
|
|
(Area::Ledger, 10, "label-only"),
|
|
(Area::Ledger, 14, "book-in-the-smallest-unit"),
|
|
(Area::Ledger, 15, "child-has-its-parents-type"),
|
|
(Area::Ledger, 16, "on-or-after-the-original"),
|
|
(Area::Ledger, 17, "reversal-evidence-is-originals"),
|
|
(Area::Ledger, 18, "assignment-is-a-fact-in-the-books"),
|
|
(Area::Ledger, 19, "refuse-rather-than-renumber"),
|
|
(Area::Ledger, 20, "warn-by-default"),
|
|
(Area::Ledger, 21, "round-once-on-the-total"),
|
|
(Area::Period, 4, "nest-never-partially-overlap"),
|
|
(Area::Period, 5, "fiscal-year-to-date-by-default"),
|
|
(Area::Statement, 5, "project-is-a-class"),
|
|
(Area::Statement, 6, "direct"),
|
|
(Area::Statement, 7, "constructive"),
|
|
(Area::Statement, 8, "year-through-as-of"),
|
|
(Area::Statement, 9, "one-project-per-line"),
|
|
(Area::Prepaid, 2, "daily"),
|
|
(Area::Prepaid, 3, "start-on-the-first"),
|
|
(Area::Prepaid, 4, "minor-unit-for-new-schedules"),
|
|
(Area::Partner, 5, "largest-remainder-first-listed"),
|
|
(Area::Partner, 6, "cumulative-from-first-close"),
|
|
(Area::Partner, 7, "running-split"),
|
|
(Area::Partner, 8, "outside-the-books"),
|
|
(Area::Partner, 9, "cash-cards-and-financing"),
|
|
(Area::Partner, 10, "capital-movement-counted-once"),
|
|
(Area::Partner, 11, "books-carrying-amount"),
|
|
(Area::Partner, 12, "labelled-cash-default-or-all"),
|
|
(Area::Partner, 13, "tax-basis-beside-book"),
|
|
(Area::Partner, 14, "running-cumulative"),
|
|
(
|
|
Area::Partner,
|
|
15,
|
|
"contract-is-property-vendor-paid-is-cash",
|
|
),
|
|
(Area::Partner, 16, "close-at-the-change"),
|
|
(Area::Partner, 17, "book-amount-with-note"),
|
|
(Area::Asset, 3, "tag-and-never-reuse"),
|
|
(Area::Asset, 5, "straight-line-by-days"),
|
|
(Area::Asset, 6, "lesser-of-value-and-basis"),
|
|
(Area::Asset, 7, "books-recorded-amounts"),
|
|
(Area::Asset, 8, "register-carries-tax-figures"),
|
|
(Area::Asset, 9, "traditional"),
|
|
(Area::Tax1099, 2, "refuse-an-unknown-year"),
|
|
(Area::Tax1099, 3, "presumed-a-check-ach-or-transfer"),
|
|
(Area::Tax1099, 4, "dated-by-the-payments-date"),
|
|
(Area::Tax1099, 5, "payees-share-only"),
|
|
(Area::Arap, 2, "lines-that-stand"),
|
|
(Area::Arap, 5, "direct-write-off"),
|
|
(Area::Arap, 7, "due-today-is-current"),
|
|
(Area::Arap, 8, "as-of-the-day"),
|
|
(Area::Arap, 9, "refuse-a-payment-before-its-document"),
|
|
(Area::Arap, 10, "ignore-case-spaces-and-hyphens"),
|
|
(Area::Arap, 11, "reverse-then-plain-entry"),
|
|
(Area::Arap, 12, "gross-when-taken"),
|
|
(Area::Arap, 13, "gross"),
|
|
(Area::Arap, 14, "refuse-with-the-remedy"),
|
|
(Area::Format, 3, "plain-ascii-transliterated-and-listed"),
|
|
(Area::Format, 4, "cr-lf"),
|
|
(Area::Format, 5, "docnum-is-the-entry-id"),
|
|
(Area::Format, 6, "everything-through-as-of"),
|
|
(Area::Format, 7, "journal-sample-columns"),
|
|
(Area::Format, 8, "closes-left-out"),
|
|
(Area::Format, 9, "no-customer-or-vendor-name"),
|
|
(Area::Format, 10, "refuse-the-entry"),
|
|
];
|