bookspec's X-H1b examples state BS-arap-4, -6 and -10 to -14 through new events and queries; the adapter runs each through the real API, none reimplemented. - settlement: `Store::settle` with the applications, the fee and the deposit account; the party is the first document's customer or vendor, so the engine itself finds an invoice mixed with a bill, two customers, a document twice, more than a document owes, a discount that needs a reason, a discount on an asset bill and a fee above the cash. Each engine error is read as the examples' word (the fee case from the one InvalidSettlement error that can arise from exact inputs). - recovery (BS-arap-11, reverse-then-plain-entry): in the write-off's fiscal year `Store::reverse_entry` of the write-off then `Store::receive_payment`; in a later year a plain entry, deposit debited and the recoveries account credited, naming the invoice. The engine has no recovery command; the two calls are the pick's own procedure. - a bill's vendor reference and duplicate reason go to `BillFields`, so `Ledger::check_vendor_ref` is what refuses a second bill; each invoice is numbered with `Ledger::next_invoice_number`; a line's own account goes to `DocumentLine`. - queries `document` (`Ledger::invoice_state`/`bill_state`) and `invoice_numbers` (the number the engine stored, read as its place in the order of issue). Wanderbooks passes all 80 examples it runs. The runner skips eleven for the options it did not pick (six new: documents-kept-apart, compare-exactly, recovery-movement, net-of-expected-discount, net-against-the-deposit, apportion-across-the-lines), so the pinned count is 11. No engine disagreed with an example. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
125 lines
4.5 KiB
Rust
125 lines
4.5 KiB
Rust
use crate::*;
|
|
|
|
use crate::queries::commands::COMMANDS;
|
|
use crate::queries::formats::FORMAT_QUERIES;
|
|
|
|
/// Check one expectation against the books as they stand: a query the
|
|
/// core answers, value by value; a format query's shape, its values left
|
|
/// to the test [`FORMAT_QUERIES`] names (returned); a query no crate
|
|
/// answers is refused.
|
|
pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
|
|
let (ex, l) = (b.ex, b.l());
|
|
let q = x.query.as_str();
|
|
let only = |given: bool, key: &str, queries: &[&str]| {
|
|
assert!(
|
|
!given || queries.contains(&q),
|
|
"{}: {q}: {key} is for {} only",
|
|
ex.id,
|
|
queries.join(" and ")
|
|
);
|
|
};
|
|
only(x.entry.is_some(), "entry", &["entry", "party_part"]);
|
|
only(x.event.is_some(), "event", &["run"]);
|
|
only(
|
|
x.asset.is_some(),
|
|
"asset",
|
|
&[
|
|
"disposal",
|
|
"depreciation_schedule",
|
|
"register_row",
|
|
"asset_basis",
|
|
],
|
|
);
|
|
only(x.schedule.is_some(), "schedule", &["schedule_plan"]);
|
|
only(
|
|
x.party.is_some(),
|
|
"party",
|
|
&["party_part", "party_totals", "party_tin_last4"],
|
|
);
|
|
only(x.basis.is_some(), "basis", &["party_totals"]);
|
|
only(x.payee.is_some(), "payee", &["vendor_1099"]);
|
|
only(
|
|
x.document.is_some(),
|
|
"document",
|
|
&["document_dates", "document"],
|
|
);
|
|
only(x.of.is_some(), "of", &["aging"]);
|
|
only(
|
|
x.code.is_some(),
|
|
"code",
|
|
&["rename_account", "set_tax_category"],
|
|
);
|
|
only(x.name.is_some(), "name", &["rename_account"]);
|
|
only(x.category.is_some(), "category", &["set_tax_category"]);
|
|
only(x.account.is_some(), "account", &["add_account"]);
|
|
only(x.accepted.is_some(), "accepted", &COMMANDS);
|
|
only(
|
|
x.refused.is_some(),
|
|
"refused",
|
|
&[
|
|
"rename_account",
|
|
"add_account",
|
|
"set_tax_category",
|
|
"period",
|
|
],
|
|
);
|
|
if COMMANDS.contains(&q) {
|
|
// A command is accepted or refused, and shows no values.
|
|
assert!(
|
|
x.values.is_none() && (x.accepted == Some(true)) != x.refused.is_some(),
|
|
"{}: {q} is a command: accepted = true, or refused, and no values",
|
|
ex.id
|
|
);
|
|
check_command(ex, l, x);
|
|
return None;
|
|
}
|
|
// Anything else shows its values; a period may be refused instead.
|
|
assert!(
|
|
x.refused.is_some() != x.values.as_ref().is_some_and(|v| !v.is_empty()),
|
|
"{}: {q} expects values (a period: values or refused)",
|
|
ex.id
|
|
);
|
|
match q {
|
|
"period" => check_period(ex, x),
|
|
"day" => check_day(ex, x),
|
|
"calendar_year" => check_calendar_year(ex, x),
|
|
"account_names" => check_account_names(ex, l, x),
|
|
"uncategorized_accounts" => check_uncategorized_accounts(ex, l, x),
|
|
"cash_flow" => check_cash_flow(b, x),
|
|
"trial_balance" => check_trial_balance(ex, l, x),
|
|
"profit_and_loss" => check_profit_and_loss(ex, l, x),
|
|
"vendor_1099_paid" => check_vendor_1099_paid(b, x),
|
|
"vendor_1099" => check_vendor_1099(b, x),
|
|
"entry" => check_entry(b, x),
|
|
"run" => check_run(b, x),
|
|
"disposal" => check_disposal(b, x),
|
|
"depreciation_schedule" => check_depreciation_schedule(b, x),
|
|
"schedule_plan" => check_schedule_plan(b, x),
|
|
"register_row" => check_register_row(b, x),
|
|
"register_totals" => check_register_totals(b, x),
|
|
"asset_basis" => check_asset_basis(b, x),
|
|
"k1_tax_basis" => check_k1_tax_basis(b, x),
|
|
"k1_reconciliation" => check_k1_reconciliation(b, x),
|
|
"balances" => check_balances(ex, l, x),
|
|
"members_equity" => check_members_equity(ex, l, &b.members, x),
|
|
"k1" => check_k1(ex, l, &b.members, x),
|
|
"party_part" => check_party_part(b, x),
|
|
"party_totals" => check_party_totals(b, x),
|
|
"party_tin_last4" => check_party_tin_last4(b, x),
|
|
"project" => check_project(b, x),
|
|
"aging" => check_aging(b, x),
|
|
"document_dates" => check_document_dates(b, x),
|
|
"document" => check_document(b, x),
|
|
"invoice_numbers" => check_invoice_numbers(b, x),
|
|
q => {
|
|
let &(_, by) = FORMAT_QUERIES
|
|
.iter()
|
|
.find(|(f, _)| *f == q)
|
|
.unwrap_or_else(|| panic!("{}: no crate answers query {q:?}", ex.id));
|
|
check_format_shape(ex, x);
|
|
return Some(by);
|
|
}
|
|
}
|
|
None
|
|
}
|