refactor: rule references cite bookspec ids

Every B-n citation in crates/, docs/, deploy/, scripts/ and .github/ now names its bookspec id BS-<area>-<n> (D-68), via scripts/rewrite-rule-refs.py: the map is parsed from docs/spec/rules.md's index, rules.md-prefixed and bare forms are rewritten, sub-references (rule 11, item 7, INVARIANT 2) survive, and plan/, docs/spec/rules.md and docs/spec/claims/ are untouched. Program-output string literals that cited a rule were reverted by hand so user-visible output and its goldens are unchanged; DatedRule.catalog, metadata no output prints, now holds BS-1099-1. One SOURCE line that cited only 'R-?' now also cites BS-statement-5.

Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
swaitsandMuse Wonder 1.0 committed 2026-11-08 19:40:22 -07:00
1 parent 7a177a3cfc
commit 489360f598
221 files changed
+1706 -1580

No files matched your search

+1 -1
View File
@@ -296,7 +296,7 @@ fn schedule_through_purchase_date_covers_one_day() {
#[test]
fn van_schedule_is_the_hand_computed_one() {
// Rank 1, computed by hand (rules.md B-15), replacing an unreviewed
// Rank 1, computed by hand (BS-asset-1), replacing an unreviewed
// golden file (2026-10-13; every row of the old file was checked
// against this computation first, and matched).
// $60,000 over 60 months is $1,000 a month. Bought 2026-01-15: January
+1 -1
View File
@@ -1,4 +1,4 @@
//! The audit's statements checks (plan P8; rules.md B-45): one test per
//! The audit's statements checks (plan P8; BS-ledger-13): one test per
//! finding code, each seeding exactly the defect the code names.
use std::collections::BTreeSet;
+1 -1
View File
@@ -281,7 +281,7 @@ impl<'a> Books<'a> {
s.rounding
);
// The engine splits a close among the members by largest
// remainder (rules.md B-13): an example closing to the members
// remainder (BS-partner-1): an example closing to the members
// says so.
assert!(
s.rounding == "largest-remainder"
+5 -5
View File
@@ -16,7 +16,7 @@ pub(crate) fn account_type(a: &AccountSpec, id: &str) -> AccountType {
}
/// The period `[from, to]` a period query covers, each date omitted
/// resolved by the one rule (rules.md B-30) on `setup.today`; panics on
/// resolved by the one rule (B-30) on `setup.today`; panics on
/// `as_of`, on an omitted date without `setup.today`, and on a period the
/// rule refuses.
pub(crate) fn period(ex: &Example, x: &Expect) -> (NaiveDate, NaiveDate) {
@@ -55,8 +55,8 @@ pub(crate) fn resolved_q_period(
defaults(ex, &q.name).statement(from, to)
}
/// The day an as-of query is made as of (omitted: `setup.today`, rules.md
/// B-30); panics on `from` or `to`.
/// The day an as-of query is made as of (omitted: `setup.today`,
/// BS-period-3); panics on `from` or `to`.
pub(crate) fn day(ex: &Example, x: &Expect) -> NaiveDate {
let q = x.query();
resolved_q_day(ex, &q).unwrap_or_else(|e| panic!("{}: {}: {e}", ex.id, x.query))
@@ -83,12 +83,12 @@ pub(crate) trait Pipe: Sized {
}
}
impl<T> Pipe for T {}
/// What an omitted date means for `ex` (rules.md B-30): its fiscal year
/// What an omitted date means for `ex` (B-30): its fiscal year
/// on `setup.today`, which `query` needs.
pub(crate) fn defaults(ex: &Example, query: &str) -> PeriodDefaults {
let today = ex.setup.today.as_deref().unwrap_or_else(|| {
panic!(
"{}: {query} omits a date: setup.today says what it means (rules.md B-30)",
"{}: {query} omits a date: setup.today says what it means (B-30)",
ex.id
)
});
+1 -1
View File
@@ -411,7 +411,7 @@ impl Books<'_> {
};
// Each write-off's own notice: identical bytes would be one
// record (plan P6 step 4), and a receipt evidences one entry
// (B-38), so a second write-off with the first's letter is
// (BS-arap-2), so a second write-off with the first's letter is
// refused before anything is journaled.
let letter = format!(
"%PDF-1.4\nFinal demand for invoice {invoice}: {}\n%%EOF\n",
@@ -218,7 +218,7 @@ pub(crate) fn a_members_close_declared_with_another_rounding_is_refused() {
});
}
/// A period's dates are the rule's (rules.md B-30): an example saying the
/// A period's dates are the rule's (BS-period-3): an example saying the
/// fiscal year to date starts on January 1 under a July fiscal year fails.
#[test]
#[should_panic(expected = "period from")]
@@ -560,7 +560,7 @@ pub(crate) fn a_members_reconciliation_shows_every_cause() {
}
/// A project named twice in `setup.projects` is refused (names are
/// unique, rules.md B-37).
/// unique, BS-statement-5).
#[test]
#[should_panic(expected = "a project named")]
pub(crate) fn a_project_named_twice_is_refused() {
@@ -225,7 +225,7 @@ impl Books<'_> {
/// Check one `run` expectation: what the `run_depreciation` event `event`
/// posted (`amount`: zero when nothing was due, or the month already had
/// its run) and, of it, what it caught up beyond its own month's
/// depreciation (`caught_up`), both listed (rules.md B-15).
/// depreciation (`caught_up`), both listed (BS-asset-1).
pub(crate) fn check_run(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
undated(ex, x);
@@ -256,7 +256,7 @@ pub(crate) fn check_run(b: &Books<'_>, x: &Expect) {
}
/// Check one `disposal` expectation: what the disposal of `asset` took, as
/// the engine computed it when posting it (rules.md B-15), every figure
/// the engine computed it when posting it (BS-asset-1), every figure
/// listed: `final_depreciation` (posted in its own entry before the
/// disposal), `catch_up_depreciation` and `excess_depreciation` (charged,
/// and credited back, in the disposal entry), `accumulated` (cleared),
@@ -288,7 +288,7 @@ pub(crate) fn check_disposal(b: &Books<'_>, x: &Expect) {
}
/// Check one `depreciation_schedule` expectation: the schedule of `asset`
/// through `as_of` (rules.md B-15), each month named (`"YYYY-MM"`) its
/// through `as_of` (BS-asset-1), each month named (`"YYYY-MM"`) its
/// depreciation, 0.00 for a month the schedule doesn't reach;
/// `accumulated` and `book_value` through `as_of`; the example names the
/// figures it shows.
@@ -326,7 +326,7 @@ pub(crate) fn check_depreciation_schedule(b: &Books<'_>, x: &Expect) {
/// Check one `schedule_plan` expectation: what the schedule's plan
/// recognizes at each month end named (`"YYYY-MM-DD"`, 0.00 at a month end
/// the plan doesn't post), and `total`, all it recognizes (rules.md B-16);
/// the plan doesn't post), and `total`, all it recognizes (BS-prepaid-1);
/// the example names the figures it shows.
pub(crate) fn check_schedule_plan(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
@@ -364,7 +364,7 @@ pub(crate) fn check_schedule_plan(b: &Books<'_>, x: &Expect) {
}
/// Check one `register_row` expectation: the asset's row of the fixed
/// asset register as of `as_of` (rules.md B-15 rules 7 and 8, B-24):
/// asset register as of `as_of` (BS-asset-1 rules 7 and 8, BS-asset-3):
/// `acquired` and `in_service` (`YYYY-MM-DD`), `cost`,
/// `accumulated_scheduled` (the schedule's), `accumulated_posted` (what
/// the books carry), `unposted` (the one less the other), `book_value`
@@ -403,7 +403,7 @@ pub(crate) fn check_register_row(b: &Books<'_>, x: &Expect) {
}
/// Check one `register_totals` expectation: the fixed asset register's
/// totals as of `as_of`, over the assets held (rules.md B-24, B-25):
/// totals as of `as_of`, over the assets held (BS-asset-3, BS-asset-4):
/// `total_cost`, `total_accumulated_scheduled`, `total_accumulated_posted`,
/// `total_book_value`, `total_depreciable_basis`, `total_tax_basis_723`,
/// `missing_basis` (how many held have none), and how it reconciles to
@@ -440,7 +440,7 @@ pub(crate) fn check_register_totals(b: &Books<'_>, x: &Expect) {
}
/// Check one `asset_basis` expectation: the asset's basis facts and the
/// tax figures they give (rules.md B-25): `rule`,
/// tax figures they give (BS-asset-4): `rule`,
/// `contributor_adjusted_basis`, `fmv_at_contribution`, `tax_basis_723`,
/// `depreciable_basis`, `built_in_gain_704c` (a loss negative), each
/// `"none"` where the asset has none (a purchase's §723 basis), and
@@ -76,7 +76,7 @@ pub(crate) fn every_balance(l: &Ledger) -> Vec<(String, Decimal, Decimal)> {
}
/// Try one command on a copy of the books, as the books' own command does
/// it (the engine's checks, then the policy's: rules.md B-31, B-32), and
/// it (the engine's checks, then the policy's: BS-ledger-10, BS-ledger-11), and
/// check it is accepted or refused for the reason given.
pub(crate) fn check_command(ex: &Example, l: &Ledger, x: &Expect) {
let mut copy = l.clone();
@@ -88,7 +88,7 @@ pub(crate) fn check_command(ex: &Example, l: &Ledger, x: &Expect) {
.as_deref()
.unwrap_or_else(|| panic!("{}: rename_account gives the name", ex.id));
copy.rename_account(account, name).inspect(|()| {
// A rename changes the label, nothing else (rules.md B-31).
// A rename changes the label, nothing else (BS-ledger-10).
assert_eq!(
copy.chart().get(account).unwrap().name,
name.trim(),
@@ -1,7 +1,7 @@
use crate::*;
/// Check one `period` expectation: the period a period report asked with
/// these dates covers, by the one rule (rules.md B-30), as `from` and
/// these dates covers, by the one rule (BS-period-3), as `from` and
/// `to`; or the rule's refusal.
pub(crate) fn check_period(ex: &Example, x: &Expect) {
match (resolved_period(ex, x), &x.refused) {
@@ -20,7 +20,7 @@ pub(crate) fn check_period(ex: &Example, x: &Expect) {
}
/// Check one `day` expectation: the day a report as of a day is made as
/// of (rules.md B-30), as `as_of`.
/// of (BS-period-3), as `as_of`.
pub(crate) fn check_day(ex: &Example, x: &Expect) {
exactly(ex, x, &["as_of".to_string()].into());
let want = date(&x.figures(&ex.id)["as_of"], &ex.id);
@@ -28,7 +28,7 @@ pub(crate) fn check_day(ex: &Example, x: &Expect) {
}
/// Check one `calendar_year` expectation: the year a calendar-year count
/// (1099s, party totals) asked without one counts (rules.md B-30).
/// (1099s, party totals) asked without one counts (BS-period-3).
pub(crate) fn check_calendar_year(ex: &Example, x: &Expect) {
assert!(
x.from.is_none() && x.to.is_none() && x.as_of.is_none(),
@@ -49,8 +49,8 @@ pub(crate) fn check_calendar_year(ex: &Example, x: &Expect) {
/// Check one `account_names` expectation: each account's name, by code,
/// as the chart holds it and every report prints it (the trial balance
/// and the profit and loss, over every date: past periods too, rules.md
/// B-31); every account listed.
/// and the profit and loss, over every date: past periods too,
/// BS-ledger-10); every account listed.
pub(crate) fn check_account_names(ex: &Example, l: &Ledger, x: &Expect) {
assert!(
x.from.is_none() && x.to.is_none() && x.as_of.is_none(),
@@ -83,7 +83,7 @@ pub(crate) fn check_account_names(ex: &Example, l: &Ledger, x: &Expect) {
/// Check one `uncategorized_accounts` expectation: every account that
/// maps to a line of the return and has no tax category, with activity or
/// not, as `"<code> <name>"`, by code (rules.md B-32).
/// not, as `"<code> <name>"`, by code (BS-ledger-11).
pub(crate) fn check_uncategorized_accounts(ex: &Example, l: &Ledger, x: &Expect) {
assert!(
x.from.is_none() && x.to.is_none() && x.as_of.is_none(),
@@ -192,13 +192,13 @@ impl Books<'_> {
/// The 1099 report a `vendor_1099_paid` or `vendor_1099` expectation
/// asks for: the calendar year of `to`, from January 1 through `to`, out
/// of the cash and financing accounts, an entry's shares resolved with
/// the members who are parties (rules.md B-19, B-33).
/// the members who are parties (BS-1099-1, BS-statement-4).
pub(crate) fn report_1099(
b: &Books<'_>,
x: &Expect,
) -> (NaiveDate, NaiveDate, ledger_core::Vendor1099Report) {
let (ex, l) = (b.ex, b.l());
// A calendar-year count, never the fiscal default (rules.md B-30):
// A calendar-year count, never the fiscal default (BS-period-3):
// both dates given.
assert!(
x.from.is_some() && x.to.is_some(),
@@ -231,7 +231,7 @@ pub(crate) fn report_1099(
/// Check one `vendor_1099_paid` expectation: each payee's payments that
/// count toward its 1099 ([`report_1099`]), a payment card's left out,
/// every payee listed (rules.md B-19, B-33).
/// every payee listed (BS-1099-1, BS-statement-4).
pub(crate) fn check_vendor_1099_paid(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
let (from, to, r) = report_1099(b, x);
@@ -254,7 +254,7 @@ pub(crate) fn check_vendor_1099_paid(b: &Books<'_>, x: &Expect) {
/// applied, and what was `paid` (counts toward its 1099),
/// `excluded_card` (a card or payment network's, Form 1099-K),
/// `undetermined` (its payment method not recorded) and `not_reportable`
/// (paid while decided not reportable); every one given (rules.md B-19).
/// (paid while decided not reportable); every one given (BS-1099-1).
pub(crate) fn check_vendor_1099(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
let name = x
@@ -299,7 +299,7 @@ pub(crate) fn check_vendor_1099(b: &Books<'_>, x: &Expect) {
/// The money party shares resolve against: the cash accounts (every
/// asset account but receivables when none are named), the cards and the
/// financing accounts (rules.md B-35 item 5).
/// financing accounts (BS-partner-3 item 5).
pub(crate) fn party_money(ex: &Example, l: &Ledger) -> MoneyAccounts {
ledger_core::parties::money_accounts(
l,
@@ -320,7 +320,7 @@ pub(crate) fn expect_party(b: &Books<'_>, x: &Expect) -> PartyId {
}
/// Check one `party_part` expectation: entry N's part for the party
/// (rules.md B-35): `resolved`, signed as a line on the party's own
/// (BS-partner-3): `resolved`, signed as a line on the party's own
/// account (debit-positive: paid or given positive, received negative),
/// the entry's `direction` (`paid`, `received` or `neither`), and what
/// of it moved as money (`cash`) and as property (`in_kind`); every one
@@ -368,7 +368,7 @@ pub(crate) fn check_party_part(b: &Books<'_>, x: &Expect) {
/// Check one `party_totals` expectation: what was `paid` to and
/// `received` from the party from `from` through `to` on `basis` (`cash`:
/// money; `all`: money and property in kind), each entry's part on its
/// root original's side (rules.md B-35 item 4); both given.
/// root original's side (BS-partner-3 item 4); both given.
pub(crate) fn check_party_totals(b: &Books<'_>, x: &Expect) {
let (ex, l) = (b.ex, b.l());
assert!(
@@ -421,8 +421,8 @@ pub(crate) fn check_party_totals(b: &Books<'_>, x: &Expect) {
);
}
/// Check one `project` expectation (rules.md B-37): the project's
/// `revenue`, `expenses` and `net` for the period (B-30 resolving omitted
/// Check one `project` expectation (BS-statement-5): the project's
/// `revenue`, `expenses` and `net` for the period (BS-period-3 resolving omitted
/// dates), the same `to_date` (every tagged line through `to`), and its
/// `unrecovered_cost` (`"none"` unless it is on spec); every one given.
/// Through ledger_core::project_figures, as the tools and the viewer.
@@ -474,7 +474,7 @@ pub(crate) fn check_project(b: &Books<'_>, x: &Expect) {
/// Check one `party_tin_last4` expectation: the last four of the party's
/// TIN the books keep (its TIN facts', else its W-9's; `""` for none:
/// rules.md B-26).
/// BS-partner-2).
pub(crate) fn check_party_tin_last4(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
assert!(
@@ -389,7 +389,7 @@ pub(crate) fn check_cash_flow(b: &Books<'_>, x: &Expect) {
/// Check one `trial_balance` expectation: each account's balance as of
/// the day, debits less credits (a credit balance negative), every
/// account listed (rules.md B-6, B-33).
/// account listed (BS-statement-1, BS-statement-4).
pub(crate) fn check_trial_balance(ex: &Example, l: &Ledger, x: &Expect) {
let as_of = day(ex, x);
let tb = trial_balance_as_of(l, as_of);
@@ -411,7 +411,7 @@ pub(crate) fn check_trial_balance(ex: &Example, l: &Ledger, x: &Expect) {
/// Check one `profit_and_loss` expectation: each revenue and expense
/// account's activity over the period on its normal side, closing entries
/// left out, and `net_income`, revenue less expenses; every revenue and
/// expense account listed (rules.md B-14, B-33).
/// expense account listed (BS-statement-3, BS-statement-4).
pub(crate) fn check_profit_and_loss(ex: &Example, l: &Ledger, x: &Expect) {
let (start, end) = period(ex, x);
let pl = profit_and_loss_for_period(l, start, end, None)
@@ -506,8 +506,8 @@ pub(crate) fn check_balances(ex: &Example, l: &Ledger, x: &Expect) {
/// Check one `members_equity` expectation: the statement of changes in
/// members' equity over the period, `"<member>.<column>"` for the columns
/// `beginning`, `contributions`, `net_income`, `distributions`, `other`
/// and `ending`; the figures named are the example's choice (rules.md
/// B-13).
/// and `ending`; the figures named are the example's choice (
/// BS-partner-1).
pub(crate) fn check_members_equity(
ex: &Example,
l: &Ledger,
@@ -92,8 +92,8 @@ impl Books<'_> {
}
}
/// Check one `k1` expectation: the K-1 worksheet over the period (rules.md
/// B-13; Schedule K-1 Item L), `"<member>.<column>"` for the columns
/// Check one `k1` expectation: the K-1 worksheet over the period (
/// BS-partner-1; Schedule K-1 Item L), `"<member>.<column>"` for the columns
/// `beginning`, `contributions_cash`, `contributions_property`,
/// `net_income`, `distributions`, `other` and `ending`; the figures named
/// are the example's choice. It needs `cash_accounts` (what is money
@@ -136,7 +136,7 @@ pub(crate) fn check_k1(ex: &Example, l: &Ledger, members: &[MemberCapital], x: &
}
}
/// The tax-basis capital worksheet for `[from, to]` (rules.md B-36), a
/// The tax-basis capital worksheet for `[from, to]` (BS-partner-4), a
/// row a member, as `k1` reads the book one: it needs the members and
/// their shares, and `cash_accounts`.
pub(crate) fn tax_capital_rows(b: &Books<'_>, x: &Expect, what: &str) -> Vec<TaxCapitalRow> {
@@ -158,7 +158,7 @@ pub(crate) fn tax_capital_rows(b: &Books<'_>, x: &Expect, what: &str) -> Vec<Tax
/// Check one `k1_tax_basis` expectation: each member's capital account
/// for `[from, to]` on the tax basis, as Schedule K-1 Item L reports it
/// (rules.md B-36), `"<member>.<line>"` for the lines `beginning`,
/// (BS-partner-4), `"<member>.<line>"` for the lines `beginning`,
/// `contributions_cash`, `contributions_property`, `net_income`, `other`,
/// `distributions` and `ending`, beside `k1`'s book figures; a line the
/// books can't know is `"open"`, with what they know so far as
@@ -201,8 +201,8 @@ pub(crate) const RECONCILING_CAUSES: [&str; 5] = [
];
/// Check one `k1_reconciliation` expectation: each member's book capital
/// less tax-basis capital at the end of `[from, to]`, by cause (rules.md
/// B-36), `"<member>.<cause>"` for `beginning`, `built_in_gain_704c`
/// less tax-basis capital at the end of `[from, to]`, by cause (
/// BS-partner-4), `"<member>.<cause>"` for `beginning`, `built_in_gain_704c`
/// (their share of the §704(c) gain or loss at contribution),
/// `property_without_basis`, `property_distributed` and `total`: the
/// example names the members it shows, each with every cause.
+1 -1
View File
@@ -1,5 +1,5 @@
//! Totals past exact arithmetic are refused, never a panic (kernel sweep
//! unit K-U4; rules.md B-21, B-28).
//! unit K-U4; BS-entry-3, BS-entry-4).
//!
//! A replayed journal line is accepted "of any size", so a restored
//! figure can sit at `Decimal::MAX`; every sum the engine makes of such
+7 -7
View File
@@ -116,7 +116,7 @@ fn pay(
) -> EntryId {
// As replay posts it: money from a vendor on receivables (1200) by
// hand, as books an earlier version wrote can hold it; the control
// guard (rules.md B-38) refuses that as new work.
// guard (BS-arap-2) refuses that as new work.
let e = ledger_core::parties::replaying(|| {
let e = l.create_entry(date, "payment");
let m = Money::new(dec(amt), Currency::USD);
@@ -219,7 +219,7 @@ fn cash_paid_per_vendor_and_who_is_reportable() {
#[test]
fn years_and_thresholds() {
let l = books();
// SOURCE: rules.md B-19 (sources/irs-1099-thresholds.md; Pub. L.
// SOURCE: BS-1099-1 (sources/irs-1099-thresholds.md; Pub. L.
// 119-21 §70433(f): payments made after December 31, 2025).
assert_eq!(default_threshold(2025), Ok(dec("600")));
assert_eq!(default_threshold(2026), Ok(dec("2000")));
@@ -805,7 +805,7 @@ fn a_debit_card_payment_from_the_bank_is_excluded_when_tagged() {
assert_eq!((v.paid, v.excluded_card), (dec("300.00"), dec("1200.00")));
}
/// Never guessed (B-19): only a company card's account presumes a card.
/// Never guessed (BS-1099-1): only a company card's account presumes a card.
/// The members' account 2100, left out of the financing accounts, carries
/// a member's card; a platform's balance 1050 carries a payment platform.
/// Each also pays by check or friends-and-family transfer (counting), so
@@ -1511,7 +1511,7 @@ fn an_undated_old_decision_is_in_force_from_the_beginning() {
assert!(b.decision_needed);
}
/// kernel::payment_bucket, every one of its 16 cases against the B-19
/// kernel::payment_bucket, every one of its 16 cases against the BS-1099-1
/// table (a complete check, not a sample).
#[test]
fn payment_bucket_is_the_table_in_all_16_cases() {
@@ -2317,7 +2317,7 @@ proptest! {
}
}
/// rules.md B-35 item 9: party totals and the 1099 worksheet never
/// BS-partner-3 item 9: party totals and the 1099 worksheet never
/// contradict. For books whose cash accounts are named, whose company
/// card is recorded as a business-card payment method (or that have
/// no card at all: without the method, 2050's name says nothing, so
@@ -2521,12 +2521,12 @@ fn card_accounts_are_the_company_cards_liabilities() {
/// plan/golden-worksheets/1099-worksheet.md before this test was run.
/// 2025 and 2026 together pin the year boundary: Dana's 300.00 on
/// 2025-12-30 counts in 2025 only, and the threshold moves from 600 to
/// 2,000 (rules.md B-19).
/// 2,000 (BS-1099-1).
#[test]
fn golden_1099_worksheet() {
let mut l = books();
// Record the card (worksheet, "With the card recorded"): Sam's 5,000
// is then a card payment, excluded and listed (B-19). books() leaves
// is then a card payment, excluded and listed (BS-1099-1). books() leaves
// it unrecorded, and other tests rely on that.
let card = l.chart().find_by_code("2100").unwrap().id;
l.add_instrument(
+1 -1
View File
@@ -1,5 +1,5 @@
//! The audit workpaper's findings for one small book, hand-verified
//! (rules.md B-45; plan/golden-worksheets/audit-workpaper.md).
//! (BS-ledger-13; plan/golden-worksheets/audit-workpaper.md).
//!
//! The fixture is a bank, prepaid insurance, capital, two revenue and two
//! expense accounts, a 12-month prepaid plan, and a vendor paid from the
+1 -1
View File
@@ -34,7 +34,7 @@ fn post(ledger: &mut Ledger, date: NaiveDate, description: &str, lines: &[(Accou
// As replay posts it: this fixture holds hand lines on the receivable
// and payable control accounts (1200, 2000), which books an earlier
// version wrote still hold and every report must read; the control
// guard (rules.md B-38) refuses them as new work.
// guard (BS-arap-2) refuses them as new work.
ledger_core::parties::replaying(|| {
let id = ledger.create_entry(date, description);
for (account, side, amount) in lines {
+17 -17
View File
@@ -34,7 +34,7 @@ fn usd(amount: u64) -> Money {
fn post(ledger: &mut Ledger, date: NaiveDate, description: &str, lines: &[(AccountId, Side, u64)]) {
// As replay posts it: these books hold hand lines on receivables or
// payables (1200, 2000), which books an earlier version wrote still
// hold and every report must read; the control guard (rules.md B-38)
// hold and every report must read; the control guard (BS-arap-2)
// refuses them as new work.
ledger_core::parties::replaying(|| {
let id = ledger.create_entry(date, description);
@@ -213,7 +213,7 @@ fn out_of_range_amount_is_rejected() {
// Big enough to overflow a sum: an error, never a panic, as soon as
// the line is added (a draft is summed before it posts: its debits,
// its parties' shares; P0 review round 3, S1). Replayed as an earlier
// version wrote it (rules.md B-28): accepted into its draft, whose
// version wrote it (BS-entry-4): accepted into its draft, whose
// post refuses it, never a panic.
let id = ledger.create_entry(date(21), "Too big");
let old = ledger.create_entry(date(21), "Too big, journaled before the bound");
@@ -268,7 +268,7 @@ fn out_of_range_amount_is_rejected() {
);
}
/// B-3 (DECISION, owner 2026-10-13: a ledger in one money holds no
/// BS-ledger-1 (DECISION, owner 2026-10-13: a ledger in one money holds no
/// fractions of its smallest unit). Regression: a payroll run posted
/// $65.27794 (found by the store's refusal property in CI, 2026-10-13).
#[test]
@@ -392,7 +392,7 @@ fn foreign_currency_line_is_rejected() {
);
}
/// R-1 / B-3: one currency throughout an entry. Even when every line
/// R-1 / BS-ledger-1: one currency throughout an entry. Even when every line
/// matches its own account's currency (a chart the ledger never builds
/// today, R-5), an entry mixing currencies is refused.
#[test]
@@ -657,7 +657,7 @@ fn random_balanced_journals_preserve_invariants() {
// As replay posts them: random lines land on receivables and
// payables by hand, as books an earlier version wrote can hold them
// (the control guard, rules.md B-38, refuses them as new work).
// (the control guard, BS-arap-2, refuses them as new work).
ledger_core::parties::replaying(|| {
for i in 0..300u32 {
let total = rng.next(100_000) + 100;
@@ -755,7 +755,7 @@ fn entry_movements_sum_to_zero() {
}
// ---------------------------------------------------------------------------
// Cash flow statement (direct method, rules.md B-14).
// Cash flow statement (direct method, BS-statement-3).
// ---------------------------------------------------------------------------
use ledger_core::NewAsset;
@@ -797,8 +797,8 @@ fn cash_flow_reconciles_to_change_in_cash() {
assert!(r.lines.iter().all(|l| l.label != "Depreciation"));
// Operating, by the direct method: collected 1,500 (class (a)); paid
// 2,500 for equipment (not a registered asset: operating, rules.md
// B-14 rule 12's limits) and 800 rent (class (d)) = -1,800. Reconciled:
// 2,500 for equipment (not a registered asset: operating,
// BS-statement-3 rule 12's limits) and 800 rent (class (d)) = -1,800. Reconciled:
// 3,200 net income - 2,500 increase in AR (4,000 billed - 1,500
// collected) - 2,500 increase in equipment = -1,800.
// Financing: +10,000 owner contribution. Sum = 8,200. Reconciles.
@@ -974,7 +974,7 @@ fn cash_flow_with_registered_asset_and_disposal() {
// payroll, and closes to accounts it finds by code. When an account with
// that code exists but is the wrong kind, it refuses, says why, and changes
// nothing, rather than posting to it or forcing the chart into its
// numbering. SOURCE: rules.md B-4 (the elements), DECISION.
// numbering. SOURCE: BS-ledger-2 (the elements), DECISION.
// ---------------------------------------------------------------------------
fn books_with(code: &str, name: &str, t: AccountType, placeholder: bool) -> Ledger {
@@ -1110,7 +1110,7 @@ fn a_close_refuses_a_3999_that_is_not_equity() {
// ---------------------------------------------------------------------------
/// A child account subdivides its parent, so it is the same kind of
/// account. SOURCE: rules.md B-4; DECISION (owner, 2026-10-13).
/// account. SOURCE: BS-ledger-2; DECISION (owner, 2026-10-13).
#[test]
fn a_child_account_has_its_parents_type() {
let mut l = Ledger::new(Currency::USD);
@@ -1168,7 +1168,7 @@ fn periods_nest_but_never_partially_overlap() {
}
/// A line names a real, postable account when it is added, not only when
/// the entry posts. DECISION (owner, 2026-10-13); rules.md B-1.
/// the entry posts. DECISION (owner, 2026-10-13); BS-entry-1.
#[test]
fn a_line_on_an_unknown_or_placeholder_account_is_refused_when_added() {
let c = fixture_company();
@@ -1202,7 +1202,7 @@ fn a_line_on_an_unknown_or_placeholder_account_is_refused_when_added() {
);
}
/// Spec (rules.md B-3; DECISION, owner 2026-10-13, after the GnuCash
/// Spec (BS-ledger-1; DECISION, owner 2026-10-13, after the GnuCash
/// cross-check): a foreign line is booked in the base currency's smallest
/// unit, half away from zero; the foreign original is kept.
#[test]
@@ -1392,7 +1392,7 @@ fn reconciling_a_card_reads_its_normal_side_and_includes_the_statement_date() {
assert_eq!(outstanding, vec![date(21), date(25)]);
}
/// B-11: closing to retained earnings with nothing to close but a swept
/// BS-period-1: closing to retained earnings with nothing to close but a swept
/// account's balance still sweeps it.
#[test]
fn a_close_sweeps_dividends_even_without_income() {
@@ -1473,7 +1473,7 @@ fn a_last_absorbs_close_gives_the_rounding_to_the_last_member() {
assert_eq!(got, vec![cents(32), cents(32), cents(41)]);
}
/// B-12: a period whose closing date already lies in a closed period
/// BS-period-2: a period whose closing date already lies in a closed period
/// can't close; the refusal names that period.
#[test]
fn a_period_ending_inside_a_closed_period_cannot_close() {
@@ -1499,7 +1499,7 @@ fn a_period_ending_inside_a_closed_period_cannot_close() {
/// Replay (for journaling stores) rebuilds invoice and bill records
/// exactly: ids follow the allocator, each record tags its entry's control
/// line and each payment its entry's (rules.md B-38), vendors tag the
/// line and each payment its entry's (BS-arap-2), vendors tag the
/// entries. A record replayed out of order is refused.
#[test]
fn replayed_documents_and_payments_rebuild_the_records() {
@@ -1611,10 +1611,10 @@ fn replayed_documents_and_payments_rebuild_the_records() {
}
// ---------------------------------------------------------------------------
// Drafts: a state, and a way out (plan P4, rules.md B-43).
// Drafts: a state, and a way out (plan P4, BS-entry-5).
// ---------------------------------------------------------------------------
/// Spec (rules.md B-43; Lean `Step.discard` and `hdrafts`): a period with
/// Spec (BS-entry-5; Lean `Step.discard` and `hdrafts`): a period with
/// an open draft can't close; once the draft is discarded it can, and
/// nothing posted moved: balances, order and ids are as they were.
#[test]
@@ -133,7 +133,7 @@ proptest! {
prop_assert_eq!(ri, kernel::reversal(&to_dec(&lines)));
}
/// The 1099 kernel (rules.md B-19): a payment split into its buckets,
/// The 1099 kernel (BS-1099-1): a payment split into its buckets,
/// and netted, the same at both types.
#[test]
fn payment_buckets_agree(lines in arb_lines()) {
@@ -277,7 +277,7 @@ proptest! {
}
}
/// rules.md B-14 rule 3: the statement of cash flows' per-entry split
/// BS-statement-3 rule 3: the statement of cash flows' per-entry split
/// (`kernel::entry_flows`, Kani `entry_flows_*`) is the same at both
/// instantiations, on balanced and unbalanced lines alike.
#[test]
@@ -324,7 +324,7 @@ proptest! {
);
}
/// rules.md B-14 rule 11: `kernel::constructive` (what a member or
/// BS-statement-3 rule 11: `kernel::constructive` (what a member or
/// lender paid or received for the company; Kani
/// `constructive_nets_to_zero`, `constructive_mirrors`) agrees at both
/// instantiations.
@@ -347,7 +347,7 @@ proptest! {
prop_assert_eq!(ti.into_iter().map(dec).collect::<Vec<_>>(), td);
}
/// rules.md B-35: a party's target, and a reversal's, are the same on
/// BS-partner-3: a party's target, and a reversal's, are the same on
/// i64 cents and on Decimal.
#[test]
fn party_target_agrees(
@@ -565,7 +565,7 @@ proptest! {
prop_assert_eq!(narrow.map(|n| Decimal::new(n, 4)), wide);
}
/// The tax summary's one rounding (rules.md B-32, B-21):
/// The tax summary's one rounding (BS-ledger-11, BS-entry-3):
/// `kernel::deductible_amount` at i64 cents (what Kani
/// `deductible_amount_rounds_once` proved) and at Decimal dollars
/// agree on the same accounts, and the Decimal result keeps the laws:
@@ -361,7 +361,7 @@ fn round_places_keeps_the_old_scale() {
}
/// `round_minor` picks the currency's own unit; a currency with none is
/// returned exactly (the FX rule, B-3).
/// returned exactly (the FX rule, BS-ledger-1).
#[test]
fn round_minor_follows_the_currency() {
use ledger_core::Currency;
+5 -5
View File
@@ -55,7 +55,7 @@ struct MPeriod {
struct Model {
/// (id, code, type, placeholder, name). The name is outside the Lean
/// model (its chart is code and type): kept here so the two agree on
/// renames' refusals, and a rename moves nothing else (rules.md B-31).
/// renames' refusals, and a rename moves nothing else (BS-ledger-10).
accounts: Vec<(u64, String, AccountType, bool, String)>,
drafts: Vec<MEntry>,
posted: Vec<MEntry>,
@@ -122,7 +122,7 @@ impl Model {
self.next_account += 1;
}
/// rules.md B-31: a name is free for `account` (None: a new one) when
/// BS-ledger-10: a name is free for `account` (None: a new one) when
/// it isn't blank, holds no nine digits in a row, and no other account
/// (all are top-level here, so all are siblings) has it, ignoring
/// capitals and surrounding space.
@@ -140,7 +140,7 @@ impl Model {
.any(|a| Some(a.0) != account && a.4.trim().to_lowercase() == key)
}
/// rules.md B-31: rename an account that exists to a free name other
/// BS-ledger-10: rename an account that exists to a free name other
/// than its own; only the name changes.
fn rename(&mut self, id: u64, name: &str) -> bool {
let Some(i) = self.accounts.iter().position(|a| a.0 == id) else {
@@ -363,7 +363,7 @@ impl Model {
// ---------------------------------------------------------------------------
// No 1200 or 2000: a line by hand on a receivables or payables account is
// refused (the control guard, rules.md B-38), which this model leaves to
// refused (the control guard, BS-arap-2), which this model leaves to
// spec_arap.rs.
const CODES: [&str; 7] = ["1000", "2100", "3000", "3999", "4000", "6000", "1900"];
/// New names: a free one, its own in other capitals and spacing, a
@@ -400,7 +400,7 @@ enum Cmd {
Reverse(usize, u32),
CreatePeriod(u32, u32),
Close(usize),
/// Rename an account (rules.md B-31): `Step.record` in the Lean model,
/// Rename an account (BS-ledger-10): `Step.record` in the Lean model,
/// whose chart has no names.
Rename(usize, usize),
}
+5 -5
View File
@@ -1,4 +1,4 @@
//! The odd cent (P3 defect 17; rules.md B-13; D-10, D-38): members closes
//! The odd cent (P3 defect 17; BS-partner-1; D-10, D-38): members closes
//! split earnings cumulatively, each member's share of everything closed
//! to these members and shares so far less what earlier closes gave them,
//! and the statement of members' equity, the K-1 worksheet and the viewer
@@ -358,7 +358,7 @@ fn a_true_up_rides_on_a_distribution_sweep() {
}
// ---------------------------------------------------------------------------
// Where a count starts: a set of members and shares (B-13; §706(d))
// Where a count starts: a set of members and shares (BS-partner-1; §706(d))
// ---------------------------------------------------------------------------
/// A reorder of the members is not a change: [A, B] closes January's cent
@@ -509,7 +509,7 @@ fn a_journaled_start_other_than_the_derived_one_is_refused() {
}
// ---------------------------------------------------------------------------
// The minor unit (B-3): whole yen, thousandths of a dinar
// The minor unit (BS-ledger-1): whole yen, thousandths of a dinar
// ---------------------------------------------------------------------------
/// P3 brief item 6: a yen book closes to its members in whole yen. 101
@@ -577,7 +577,7 @@ fn a_dinar_book_closes_to_members_in_thousandths() {
/// A currency ISO 4217 gives no minor unit (gold, XAU) splits to the finest
/// amount a line may carry (kernel::MAX_LINE_SCALE places), so every amount
/// is a whole number of the unit it splits to and no member is ever one
/// from exact (B-13's precondition). 0.019 at 33.33% / 33.33% / 33.34% is
/// from exact (BS-partner-1's precondition). 0.019 at 33.33% / 33.33% / 33.34% is
/// exactly 0.0063327 / 0.0063327 / 0.0063346: each member takes theirs.
/// Split to cents instead, the floors (0.00 each) left 0.019, a cent and
/// 0.009 of one, all of it to the largest remainder: C 0.019, A and B
@@ -835,7 +835,7 @@ fn nth_month(i: usize) -> (i32, u32) {
proptest! {
#![proptest_config(ProptestConfig::with_cases(512))]
/// Oracle: rules.md B-13 and close INVARIANT 6, hand-stated: after
/// Oracle: BS-partner-1 and close INVARIANT 6, hand-stated: after
/// any history (closes under the legacy rules, then months closed to
/// the members in either order, to retained earnings, or left open),
/// every members close hands out exactly its net; once a cumulative
+12 -12
View File
@@ -389,7 +389,7 @@ proptest! {
/// A fiscal year start as the books may hold one: any month and day 2001
/// has (a new setting is the first of a month; replay takes any day every
/// year has, rules.md B-28).
/// year has, BS-entry-4).
fn arb_fiscal_start() -> impl Strategy<Value = (u32, u32)> {
(1u32..=12, 1u32..=31).prop_filter("a day 2001 has", |&(m, d)| {
NaiveDate::from_ymd_opt(2001, m, d).is_some()
@@ -411,7 +411,7 @@ fn arb_calendar_day() -> impl Strategy<Value = NaiveDate> {
proptest! {
#![proptest_config(ProptestConfig::with_cases(5000))]
/// rules.md B-30, PeriodDefaults INVARIANTS 1-5, for every fiscal
/// BS-period-3, PeriodDefaults INVARIANTS 1-5, for every fiscal
/// year start the books hold, every today in the calendar, and every
/// mix of given and omitted dates: the resolved dates are the given
/// ones or the defaults, never swapped; Err exactly when the resolved
@@ -596,7 +596,7 @@ mod p3 {
proptest! {
#![proptest_config(ProptestConfig::with_cases(500))]
/// depreciation_schedule INVARIANT 5 (rules.md B-15; defect 22): accumulated depreciation never falls,
/// depreciation_schedule INVARIANT 5 (BS-asset-1; defect 22): accumulated depreciation never falls,
/// never exceeds cost − salvage, is 0 before the in-service date and
/// cost − salvage from the life's last day on; each schedule's lines
/// sum to its accumulated and none is negative. Sampled through: every
@@ -680,7 +680,7 @@ proptest! {
prop_assert_eq!(scheduled_book_value(a, on).unwrap(), want.book_value);
}
/// B-15 rule 3 (defect 22), against arithmetic written here: through
/// BS-asset-1 rule 3 (defect 22), against arithmetic written here: through
/// any day k of the life's final month (its d days), accumulated is C +
/// (D − C) × k / d rounded half up to the cent, C the exact charge of
/// the months before (D × each month's days held over its days, over
@@ -719,7 +719,7 @@ proptest! {
}
}
/// B-15 rule 4 (depreciation_schedule INVARIANT 6; P3 depreciation brief 2.3, R1, R8): through every
/// BS-asset-1 rule 4 (depreciation_schedule INVARIANT 6; P3 depreciation brief 2.3, R1, R8): through every
/// month end of the life, the schedule is the pre-P3 running total
/// (USD, a two-place currency), except where the exact cumulative is a
/// half-cent tie, which the old 28-digit Decimal quotients could round
@@ -895,8 +895,8 @@ fn arb_basis_rule() -> impl Strategy<Value = ledger_core::BasisRule> {
proptest! {
#![proptest_config(ProptestConfig::with_cases(5000))]
/// kernel::basis_figures INVARIANTS 1-4 on Decimal money (rules.md
/// B-25): a purchase depreciates from cost and has no §723 basis or
/// kernel::basis_figures INVARIANTS 1-4 on Decimal money (
/// BS-asset-4): a purchase depreciates from cost and has no §723 basis or
/// built-in gain; a contribution's §723 basis is the adjusted basis,
/// its built-in gain fair market value less that basis, negative
/// exactly when the basis exceeds the value; carryover depreciates
@@ -937,7 +937,7 @@ proptest! {
proptest! {
#![proptest_config(ProptestConfig::with_cases(256))]
/// rules.md B-37 item 3: for any tags and any period, the projects'
/// BS-statement-5 item 3: for any tags and any period, the projects'
/// figures plus the untagged lines' are the period's profit and loss
/// (no line counted twice or lost), each through
/// ledger_core::project_figures.
@@ -1002,7 +1002,7 @@ proptest! {
prop_assert_eq!(exp_sum + untagged_exp, all.total_expenses);
}
/// rules.md B-37 item 7: the snapshot's contribution is
/// BS-statement-5 item 7: the snapshot's contribution is
/// project_to_date's net, revenue less direct costs, whatever the
/// tags and sides (a refund debits revenue, a reimbursement credits an
/// expense below zero): the accounts sum to the totals, each month's
@@ -1091,7 +1091,7 @@ proptest! {
}
}
/// rules.md B-37 item 3: project_entries codes its own signs, so the
/// BS-statement-5 item 3: project_entries codes its own signs, so the
/// posted entries' project amounts must sum to project_to_date's net
/// (with no entry dated after the day), whatever the tags, the sides,
/// a tagged balance-sheet line, or drafts beside them.
@@ -1145,7 +1145,7 @@ proptest! {
proptest! {
#![proptest_config(ProptestConfig::with_cases(2000))]
/// rules.md B-26 (P7): a TIN is found and masked however its groups
/// BS-partner-2 (P7): a TIN is found and masked however its groups
/// are separated — a hyphen, a dot, a comma, a parenthesis, a slash,
/// an underscore, or any run of spaces — and what merely looks like
/// one is not: an amount's thousands separators (1,234,567.89 is
@@ -1154,7 +1154,7 @@ proptest! {
/// setting's kind (company.duns), never a party field. The ACH payment
/// methods' lines get the same exemption in P4b S4's Kind; until then
/// the filing scan's narrow shapes keep a bank export's routing
/// numbers out of the rule (rules.md B-26).
/// numbers out of the rule (BS-partner-2).
#[test]
fn tin_shapes_with_any_separator_are_found(
sep in prop::sample::select(vec![
+2 -2
View File
@@ -239,7 +239,7 @@ fn recurring_entries_generate_drafts_never_posts() {
let _ = b.revenue;
}
/// Regression (B-12, found by the store's refusal property on
/// Regression (BS-period-2, found by the store's refusal property on
/// 2026-10-13): a recurring occurrence dated in a closed period is
/// refused, leaves nothing behind, and is reported as needing a human.
#[test]
@@ -825,7 +825,7 @@ fn plan_values(plan: Vec<(NaiveDate, Decimal)>) -> Vec<serde_json::Value> {
/// A year of prepaid insurance at 100.00 a month (three months posted,
/// 900.00 left) and three months of deferred revenue at 333.33, 333.33,
/// 333.34 (the last period takes the rounding, so the three sum to
/// 1,000.00 exactly: rules.md B-16).
/// 1,000.00 exactly: BS-prepaid-1).
#[test]
fn golden_amortization_plans() {
let mut b = books();
+2 -2
View File
@@ -458,7 +458,7 @@ fn counts_are_positive_whole_numbers() {
}
/// `Kind::Terms`: canonicalized through [`ledger_core::Terms`], so two
/// spellings of one agreement are one value (rules.md B-39).
/// spellings of one agreement are one value (BS-arap-3).
#[test]
fn terms_keep_one_canonical_spelling() {
let terms = |s: &str| checked("invoicing.default_terms", json!(s));
@@ -575,7 +575,7 @@ fn contact_details_are_in_the_company_profile() {
/// Replay checks the new kinds by shape, never by a later version's
/// bounds: a count is a positive whole number, terms any string, and a
/// method list of objects with their fields (rules.md B-28).
/// method list of objects with their fields (BS-entry-4).
#[test]
fn replay_shapes_the_new_kinds() {
let count = key("invoicing.unsent_days").unwrap();
+9 -9
View File
@@ -4,7 +4,7 @@
//! Oracles are the spec blocks in the `ledger-core` interface (doc comments
//! on `Ledger::create_invoice`, `create_bill`, `receive_payment`, `pay_bill`,
//! `arap::aging_bucket`, the `ControlAccount` / `ControlAccountMismatch`
//! docs) and `docs/spec/rules.md` B-18. Expected values are computed by hand
//! docs) and BS-arap-1. Expected values are computed by hand
//! from those, never from the code under test.
use std::str::FromStr;
@@ -124,7 +124,7 @@ fn fingerprint(l: &Ledger) -> String {
out
}
/// Expected bucket index from rules.md B-18, written independently:
/// Expected bucket index from BS-arap-1, written independently:
/// 0 Current (on or before due), 1: 1-30, 2: 31-60, 3: 61-90, 4: 90+.
fn expected_bucket(due: NaiveDate, as_of: NaiveDate) -> usize {
let days = (as_of - due).num_days();
@@ -288,7 +288,7 @@ fn derive_status_examples() {
// ------------------------------------------------------------ aging_bucket
/// Oracle: aging_bucket SCENARIO 1 and B-18 DECISION: due today is Current.
/// Oracle: aging_bucket SCENARIO 1 and BS-arap-1 DECISION: due today is Current.
#[test]
fn aging_due_today_is_current() {
let r = aging_bucket(d(2026, 10, 13), d(2026, 10, 13), dec("42.00"));
@@ -307,7 +307,7 @@ fn aging_not_yet_due_is_current() {
}
/// Oracle: aging_bucket SCENARIOS 2-5 at each edge (1, 30, 31, 60, 61, 90,
/// 91 days past due), B-18.
/// 91 days past due), BS-arap-1.
#[test]
fn aging_boundaries_by_days_past_due() {
let due = d(2026, 1, 1);
@@ -795,7 +795,7 @@ fn receive_payment_partial_then_full() {
}
/// Oracle: receive_payment SCENARIO 1 (amount not positive) — refusal leaves
/// the books unchanged (B-8 general refusal rule, as for post_entry).
/// the books unchanged (BS-ledger-4 general refusal rule, as for post_entry).
#[test]
fn receive_payment_refuses_non_positive_amount() {
let (mut l, cash) = books();
@@ -984,7 +984,7 @@ fn pay_bill_refuses_bad_amounts_books_unchanged() {
// ------------------------------------------------------------------ aging
/// Oracle: ar_aging doc (one row per customer with an outstanding balance,
/// bucketed by days past due) and B-18 buckets; fully paid customers get no
/// bucketed by days past due) and BS-arap-1 buckets; fully paid customers get no
/// row.
///
/// ASSUMED: rows carry the customer's name and their order is unspecified
@@ -1040,7 +1040,7 @@ fn ar_aging_example() {
}
/// Oracle: ap_aging doc (one row per vendor with an outstanding balance) and
/// B-18 (1-30 and 61-90 buckets).
/// BS-arap-1 (1-30 and 61-90 buckets).
#[test]
fn ap_aging_example() {
let (mut l, cash) = books();
@@ -1124,7 +1124,7 @@ proptest! {
/// unchanged); DocumentStatus docs (status law); Invoice::balance doc;
/// conservation (1200 balance = sum of open invoice balances, 4000 =
/// sum of invoice totals, cash = sum received, since every movement on
/// them comes through invoices and payments); ar_aging doc + B-18
/// them comes through invoices and payments); ar_aging doc + BS-arap-1
/// (each open balance in exactly one bucket; buckets sum to open
/// balances; due today is Current).
#[test]
@@ -1215,7 +1215,7 @@ proptest! {
/// Oracles: pay_bill INVARIANTS 1-2 and SCENARIO 1; DocumentStatus docs;
/// Bill::balance doc; conservation (2000 = sum of open bill balances,
/// 6999 = sum of bill totals, cash = -sum paid); every payment entry
/// tagged with its vendor; ap_aging doc + B-18.
/// tagged with its vendor; ap_aging doc + BS-arap-1.
#[test]
fn prop_bills_and_payments_conserve(
docs in proptest::collection::vec(doc_strategy(), 1..6),
+4 -4
View File
@@ -1,6 +1,6 @@
//! Spec-derived tests for an asset's basis facts and tax figures
//! (rules.md B-25), its two dates and its two accumulated figures
//! (rules.md B-15, B-24): `BasisRule`, `Sec704cMethod`, `AssetBasis`
//! (BS-asset-4), its two dates and its two accumulated figures
//! (BS-asset-1, BS-asset-3): `BasisRule`, `Sec704cMethod`, `AssetBasis`
//! (`check`, `check_journaled`, `check_legacy_journaled`),
//! `Ledger::set_asset_basis` / `replay_set_asset_basis` /
//! `replay_set_asset_tax_basis`, `Asset::basis_figures`,
@@ -942,7 +942,7 @@ fn posted_follows_the_entries_dates() {
assert_eq!(l.live_depreciation_run(id, "2026-01"), None);
}
/// A reversal of the reversal reinstates the run (B-9), and the run counts
/// A reversal of the reversal reinstates the run (BS-ledger-5), and the run counts
/// again: the month is not due twice (review R2).
#[test]
fn a_reinstated_run_counts_and_is_live() {
@@ -963,7 +963,7 @@ fn a_reinstated_run_counts_and_is_live() {
/// −100.00, as the trial balance does (review R2). No command can write one
/// any more (D-73: a reversal is dated on or after its original, so
/// `reverse_entry` refuses it), but a journal an earlier version wrote holds
/// them and replays as it was (B-28): this test replays one.
/// them and replays as it was (BS-entry-4): this test replays one.
#[test]
fn a_reversal_dated_before_its_run_matches_the_trial_balance() {
let (mut l, a, id, e) = one_run();
+5 -5
View File
@@ -1,4 +1,4 @@
//! Spec-derived tests for asset tags and serial numbers (rules.md B-24) and
//! Spec-derived tests for asset tags and serial numbers (BS-asset-3) and
//! the fixed asset register (`reports::fixed_asset_register`).
//!
//! Every expected value comes from the written specification: the doc
@@ -6,7 +6,7 @@
//! `assets::check_asset_tag`, `assets::check_serial`, `assets::tag_key`,
//! `Ledger::set_asset_tag`, `check_asset_tag_for`, `set_asset_serial`,
//! `asset_by_tag`, `next_asset_tag`, `fixed_asset_register` and
//! `AssetRegister`, and `docs/spec/rules.md` B-15 and B-24. Depreciation
//! `AssetRegister`, and BS-asset-1 and BS-asset-3. Depreciation
//! amounts are worked by hand (straight line, whole months) or, for
//! mid-month dates, taken from the already-tested building block
//! `accumulated_scheduled_through`. Nothing is read back from the code under
@@ -160,7 +160,7 @@ fn check_asset_tag_accepts_the_documented_forms() {
assert!(check_asset_tag(&longest).is_ok());
}
/// B-24 says 1–32 characters: the constant agrees with the rule.
/// BS-asset-3 says 1–32 characters: the constant agrees with the rule.
#[test]
fn max_asset_tag_len_is_32_per_b24() {
assert_eq!(MAX_ASSET_TAG_LEN, 32);
@@ -608,7 +608,7 @@ fn serial_ok(s: &str) -> bool {
proptest! {
#![proptest_config(ProptestConfig::with_cases(256))]
/// B-24 / set_asset_tag INVARIANTS 1-3 and set_asset_serial SCENARIO 1
/// BS-asset-3 / set_asset_tag INVARIANTS 1-3 and set_asset_serial SCENARIO 1
/// over random command sequences, against a model built from the spec.
#[test]
fn prop_tag_commands_keep_the_invariants(cmds in proptest::collection::vec(arb_cmd(), 1..40)) {
@@ -1088,7 +1088,7 @@ fn register_of_no_assets_is_empty() {
/// 1,000.00 and June's 10/30: 5,333.33 scheduled. Before P3 the disposed
/// schedule ended in a plug, so the register showed 12,000.00 and 0.00.
/// The same in the life's final month: on 2026-12-15, 11,483.87. Book
/// value is cost less what the books carry (defect 13, rules.md B-15 rule
/// value is cost less what the books carry (defect 13, BS-asset-1 rule
/// 8): the fixture's runs, January to March, 3,000.00, so 9,000.00.
#[test]
fn register_as_of_a_day_before_a_same_month_disposal_is_prorated() {
+13 -13
View File
@@ -1,8 +1,8 @@
//! Spec-derived tests for fixed assets (depreciation, disposal) and payroll.
//!
//! Every expected value here is a literal worked by hand from the written
//! specification (the interface doc comments, `docs/spec/rules.md` B-15 and
//! B-22, and IRS Pub. 15 in `docs/spec/sources/irs-payroll.md`), or a law the
//! specification (the interface doc comments, BS-asset-1 and
//! BS-asset-2, and IRS Pub. 15 in `docs/spec/sources/irs-payroll.md`), or a law the
//! specification states. Nothing is read back from the code under test and
//! then asserted.
@@ -274,7 +274,7 @@ const PLAN_CASH: AccountId = 100;
// ------------------------------------------------- depreciation schedule
/// Oracle: B-15 straight line, (cost − salvage) / life = 12000 / 12 = 1000.00
/// Oracle: BS-asset-1 straight line, (cost − salvage) / life = 12000 / 12 = 1000.00
/// per full month; a purchase on the 1st makes every month full.
#[test]
fn full_months_each_take_one_twelfth_b15() {
@@ -316,7 +316,7 @@ fn schedule_clamps_to_end_of_life() {
assert_eq!(s.last().unwrap().book_value, d("0.00"));
}
/// Oracle: B-15 partial months prorated by days; monthly 620/2 = 310.00.
/// Oracle: BS-asset-1 partial months prorated by days; monthly 620/2 = 310.00.
/// Bought 2026-01-15: Jan holds 15..31 = 17/31 → 170.00; Feb full 310.00;
/// life ends 2026-03-15 so Mar holds 1..14 = 14/31 → 140.00. 17/31 + 14/31
/// = one full month, and the total is exactly 620.00.
@@ -368,7 +368,7 @@ fn last_month_trues_up_unequal_month_lengths_b15() {
);
}
/// Oracle: B-15 "salvage never depreciated": cost 5000, salvage 1000, life 4
/// Oracle: BS-asset-1 "salvage never depreciated": cost 5000, salvage 1000, life 4
/// → 1000.00/month, book value stops at 1000.00 forever.
#[test]
fn salvage_value_is_never_depreciated_b15() {
@@ -387,7 +387,7 @@ fn salvage_value_is_never_depreciated_b15() {
);
}
/// Oracle: B-21/interface "exact cents … never a penny off": 1000.00 over 3
/// Oracle: BS-entry-3/interface "exact cents … never a penny off": 1000.00 over 3
/// months cannot split evenly; months are 333.33 or 333.34 and sum to
/// exactly 1000.00.
#[test]
@@ -567,7 +567,7 @@ fn defect22_a_disposed_assets_schedule_stops_at_its_disposal_day() {
/// cumulative 100,000 × m / 12, rounded half up to the yen (8,333.33 →
/// 8,333; 16,666.67 → 16,667; 25,000; ...), so months alternate 8,333 and
/// 8,334 and sum to 100,000. Every one is whole yen, so it can post (an
/// entry refuses a fraction of the minor unit, B-3).
/// entry refuses a fraction of the minor unit, BS-ledger-1).
#[test]
fn jpy_depreciation_posts_whole_yen() {
let mut a = asset("100000", "0", 12, date(2026, 1, 1));
@@ -667,7 +667,7 @@ fn disposal_loss_is_negative() {
assert_eq!(scrap.gain_loss, d("-6000.00"));
}
/// Oracle: B-15 + gain law: after full life, book value = salvage 1000.00,
/// Oracle: BS-asset-1 + gain law: after full life, book value = salvage 1000.00,
/// selling for 1000.00 is neither gain nor loss.
#[test]
fn disposal_after_full_life_at_salvage_is_break_even() {
@@ -742,7 +742,7 @@ fn assert_asset_refused(new: NewAsset, l: &mut Ledger, check: impl Fn(&LedgerErr
}
/// Oracle: register_asset SCENARIO 1 "description is blank: SHOULD refuse";
/// refusal leaves the books unchanged (B-8 / post_entry INVARIANT 3 spirit).
/// refusal leaves the books unchanged (BS-ledger-4 / post_entry INVARIANT 3 spirit).
#[test]
fn register_asset_refuses_empty_description() {
let (mut l, a) = fixture();
@@ -1226,7 +1226,7 @@ fn run_payroll_refuses_zero_gross() {
}
/// Oracle: validate_payroll/run_payroll take a cash account; an unknown one
/// cannot be credited (B-1 / R-1 "no unknown accounts").
/// cannot be credited (BS-entry-1 / R-1 "no unknown accounts").
///
/// ASSUMED: the refusal comes before posting; variant unspecified.
#[test]
@@ -1251,7 +1251,7 @@ fn run_payroll_refuses_wrong_type_control_account() {
);
}
/// Oracle: B-12 "a closed period takes no new postings"; remit doc "rejects
/// Oracle: BS-period-2 "a closed period takes no new postings"; remit doc "rejects
/// dates in closed periods".
#[test]
fn payroll_and_remit_refuse_closed_period() {
@@ -1312,7 +1312,7 @@ fn period_end(p: &str) -> NaiveDate {
proptest! {
#![proptest_config(ProptestConfig::with_cases(256))]
/// Oracle: B-15 laws — a full schedule sums to exactly cost − salvage;
/// Oracle: BS-asset-1 laws — a full schedule sums to exactly cost − salvage;
/// amounts are non-negative whole cents; accumulated is the running sum
/// and non-decreasing; book value = cost − accumulated, never rises, never
/// below salvage, ends at salvage; months are consecutive from the
@@ -1367,7 +1367,7 @@ proptest! {
prop_assert_eq!(scheduled_book_value(&a, before).unwrap(), a.cost.amount);
}
/// Oracle: B-15 partial months by days + interface "the last month absorbs
/// Oracle: BS-asset-1 partial months by days + interface "the last month absorbs
/// the drift". When (cost − salvage) / life is a whole number of cents M
/// and the purchase is after the 1st, the middle months are each exactly
/// M and the partial first and last months together are exactly M.
+8 -8
View File
@@ -4,7 +4,7 @@
//! (ledger_core::calendar), and what can't be computed exactly is refused,
//! never wrapped or panicked on (P0 review round 3, finding S1: a panic
//! stops the books server). The bounds are the commands' only: replay
//! accepts every line an earlier version accepted (rules.md B-28, posted
//! accepts every line an earlier version accepted (BS-entry-4, posted
//! is forever; P0 review round 4), so each bound here has its pair, a
//! replay of an old line past it, accepted.
//!
@@ -617,7 +617,7 @@ fn replayed_bases_and_shares_past_the_limit_are_accepted() {
);
}
/// A replayed payment is as journaled: no bound (rules.md B-28), and no
/// A replayed payment is as journaled: no bound (BS-entry-4), and no
/// refusal: it tags the line of its entry that carries it, or (an entry
/// it doesn't match) nothing. The command's bound is what the invoice
/// owes (Overpayment).
@@ -719,7 +719,7 @@ fn disposal_proceeds_and_dates_are_bounded() {
// Replay keeps what every version checked: no disposal twice, no
// negative proceeds. The date floor (the acquired date, P3) is a
// command's: replay accepts a disposal before it, which every earlier
// version's commands refused anyway (rules.md B-28: replay accepts
// version's commands refused anyway (BS-entry-4: replay accepts
// more, never less).
assert_eq!(
b.ledger
@@ -744,12 +744,12 @@ fn disposal_proceeds_and_dates_are_bounded() {
}
/// D-75 (owner, 2026-11-08): a new line's foreign amount and its rate take
/// at most ten decimal places each, as a base amount does (B-28), so the
/// at most ten decimal places each, as a base amount does (BS-entry-4), so the
/// product is exact (at most twenty places, under Decimal's 28) and the
/// booked amount is rounded once. Found by the K-U1 review: a 26-place
/// foreign amount times 0.005 books 0.01 though the exact product is under
/// half a cent, because Decimal rounded the product to 28 places first.
/// Replay is exempt (B-28): an older line keeps its figures.
/// Replay is exempt (BS-entry-4): an older line keeps its figures.
#[test]
fn a_foreign_amount_and_a_rate_take_at_most_ten_places() {
let dec = |s: &str| s.parse::<Decimal>().unwrap();
@@ -963,7 +963,7 @@ fn new_asset(
}
}
/// B-3 (P3): a new asset's cost and salvage are in the currency's minor
/// BS-ledger-1 (P3): a new asset's cost and salvage are in the currency's minor
/// unit (every depreciation and disposal line derives from them, and a
/// line finer than a cent never posts). Its replay pair: an asset an
/// earlier version took in tenths of a cent opens, and its schedule is
@@ -998,7 +998,7 @@ fn an_asset_cost_finer_than_a_cent_is_refused() {
assert_eq!(s[11].accumulated, "1200.005".parse::<Decimal>().unwrap());
}
/// B-28 (P3: lives past 9999, plan/served.md defect 22): a new asset's
/// BS-entry-4 (P3: lives past 9999, plan/served.md defect 22): a new asset's
/// last day of depreciation is at most 9999-12-31, the calendar's last
/// day, so every month of its life is one the books can post. A life
/// ending on that day is taken (P0 bounded the life's exclusive end, one
@@ -1040,7 +1040,7 @@ fn a_life_ending_after_it_is_refused() {
}
}
/// B-28 (P3): a daily schedule's last day is in the calendar: one month
/// BS-entry-4 (P3): a daily schedule's last day is in the calendar: one month
/// from 9999-12-15 covers through 10000-01-14, refused; one month from
/// 9999-12-01 ends on 9999-12-31, taken. Replay takes either.
#[test]
+29 -29
View File
@@ -1,4 +1,4 @@
//! The statement of cash flows (rules.md B-14), from the rule and its
//! The statement of cash flows (BS-statement-3), from the rule and its
//! sources, never from the implementation.
//!
//! Every expected figure is worked by hand in the test's doc comment from
@@ -53,7 +53,7 @@ impl Books {
// As replay posts it: these books hold hand lines on receivables
// or payables (1200, 2000), which books an earlier version wrote
// still hold and every report must read; the control guard
// (rules.md B-38) refuses them as new work.
// (BS-arap-2) refuses them as new work.
ledger_core::parties::replaying(|| {
let e = self.l.create_entry(date, desc);
for &(code, side, amount) in lines {
@@ -168,7 +168,7 @@ fn s(t: &str) -> String {
t.to_string()
}
/// The laws every statement keeps (rules.md B-14 rules 8 and 9): each
/// The laws every statement keeps (BS-statement-3 rules 8 and 9): each
/// section is its lines, and its kinds; the sections are the change in
/// cash; net income and the reconciling items are operating.
fn foots(cf: &CashFlowStatement) {
@@ -205,7 +205,7 @@ fn no_distribution(cf: &CashFlowStatement) {
/// The minimal reproduction of defect 1. Property contributed (Dr
/// Equipment 2,340 / Cr Capital), the asset registered, the entry reversed
/// the same day. No cash moved, and the entry and its reversal cancel
/// (rules.md B-14 rules 1, 6): every section 0.00, no lines, no
/// (BS-statement-3 rules 1, 6): every section 0.00, no lines, no
/// disclosures, footing 0 / 0 / 0. Before the fix: investing −2,340.00
/// against a change in cash of 0.00 (the reversal's credit to the
/// equipment account belonged to no section).
@@ -276,7 +276,7 @@ fn defect1_reversed_contributions_foot_regression() {
/// | 22 | 03-20 | reverses #9 | | |
/// | 23 | 03-30 | API credits on the card | 6300 42.75 | 2050 |
///
/// By hand, the year to 2026-03-31 (rules.md B-14; D-42 for what the
/// By hand, the year to 2026-03-31 (BS-statement-3; D-42 for what the
/// members paid):
/// - Operating: the members paid #1 85.00, #2 12.97, #3 99.00, #6 7.49,
/// #21 216.40, #7 129.00 and #20 46.38 (the prepaid domain) for the
@@ -876,7 +876,7 @@ fn a_property_contribution_is_a_noncash_disclosure() {
assert_eq!(n.label, format!("Laptop contributed (#{e})"));
}
/// D-42, rules.md B-14 rule 11 (ASC 230 is silent on a payment a third
/// D-42, BS-statement-3 rule 11 (ASC 230 is silent on a payment a third
/// party makes on the entity's behalf; PwC FSP 6.9.3.1, DART Roadmap 7.2
/// and BDO Blueprint 3.4 present it by substance, as constructive receipt
/// and disbursement). An expense a member pays personally (Dr Supplies
@@ -1011,7 +1011,7 @@ fn equipment_a_lender_paid_for_is_borrowed_and_invested() {
assert_eq!(cf.net_change_in_cash, x("-500.00"));
}
/// The expense-to-capital case (rules.md B-14 rule 11): a member pays a
/// The expense-to-capital case (BS-statement-3 rule 11): a member pays a
/// vendor for the company and the books credit the member's capital (Dr
/// Supplies 80 / Cr Capital — Member A), no cash. The member paid cash to
/// a third party on the company's behalf, as through 2100; only the form
@@ -1150,7 +1150,7 @@ fn equipment_on_the_sellers_credit_stays_noncash_and_flagged() {
assert!(w.message.contains("borrowed and spent"), "{}", w.message);
}
/// rules.md B-14 rule 6 with rule 11: a payment a member made for the
/// BS-statement-3 rule 6 with rule 11: a payment a member made for the
/// company and its reversal, both in February, drop out together (their
/// flows, constructive cash included, are exact negatives: Kani
/// `constructive_mirrors`); no line, no disclosure, no total moves. The
@@ -1351,7 +1351,7 @@ fn interest_and_guaranteed_payments_charged_to_a_creditor_stay_noncash() {
);
}
/// rules.md B-14 rule 6 (B-9: a correction undoes what it corrects): an
/// BS-statement-3 rule 6 (BS-ledger-5: a correction undoes what it corrects): an
/// entry and its reversal both in the period drop out of every line and
/// disclosure, and no total moves (their flows are exact negatives, Kani
/// `entry_flows_of_a_reversal_mirror`).
@@ -1390,7 +1390,7 @@ fn an_entry_and_its_reversal_in_the_period_drop_out() {
assert_eq!(cf.net_change_in_cash, before.net_change_in_cash);
}
/// rules.md B-14 rule 6: a reversal shown alone (its original in an
/// BS-statement-3 rule 6: a reversal shown alone (its original in an
/// earlier period) is labelled "Reversal of #N — <N's description>" and
/// listed under its original's kind, never as a distribution (D1-c).
#[test]
@@ -1414,7 +1414,7 @@ fn a_reversal_alone_is_labelled_reversal_of() {
no_distribution(&cf);
}
/// rules.md B-14 rules 4 and 6: a reversal takes its chain root's
/// BS-statement-3 rules 4 and 6: a reversal takes its chain root's
/// sections, class and kind, with its own sign. Reversing January's cash
/// sale at a 300 gain in February: investing −500 under "Proceeds from
/// sales of property and equipment", G +300 (the gain, reversed, is still
@@ -1766,7 +1766,7 @@ fn operating_classes_follow_asc_230_10_45_25() {
/// ASC 230-10-45-28(b): depreciation is an item of net income with no
/// cash effect, a reconciling item; it is not an investing or financing
/// activity, so nothing is disclosed (rules.md B-14 rule 7).
/// activity, so nothing is disclosed (BS-statement-3 rule 7).
#[test]
fn depreciation_is_reconciling_not_disclosed() {
let mut b = funded();
@@ -1862,7 +1862,7 @@ fn operating_reconciliation_ties_to_operating_cash() {
);
}
/// rules.md B-11 and B-14 rule 10: a period close moves earnings into
/// BS-period-1 and BS-statement-3 rule 10: a period close moves earnings into
/// equity; it earns and spends nothing, so it is never in the statement.
#[test]
fn closing_entries_never_appear() {
@@ -1881,7 +1881,7 @@ fn closing_entries_never_appear() {
assert!(!text.contains(&format!("entry: {close},")));
}
/// The period is [start, end] inclusive (rules.md B-14 rule 1): a
/// The period is [start, end] inclusive (BS-statement-3 rule 1): a
/// contribution on the start date is a flow, not opening cash.
#[test]
fn cash_flow_starts_counting_on_the_start_date() {
@@ -1921,7 +1921,7 @@ fn a_transfer_between_cash_accounts_is_not_a_flow() {
assert!(cf.noncash_disclosures.is_empty());
}
/// Review round 2, footing in odd shapes (rules.md B-14 rules 1, 6, 9,
/// Review round 2, footing in odd shapes (BS-statement-3 rules 1, 6, 9,
/// 11), by hand:
/// - two cash accounts in one entry, a transfer less its fee (Dr Savings
/// 99, Dr Supplies 1 / Cr Cash 100): only the net, −1, moves cash,
@@ -2035,7 +2035,7 @@ fn a_note_received_for_equipment_is_disclosed() {
/// ASC 230-10-50-4: a trade-in. A new vehicle (2,000, on 1520) for the
/// old equipment (cost 1,000 on 1500, accumulated 800, gain 300) and
/// 1,500 cash: investing −1,500 and an exchange of 500 disclosed. Within
/// one cost account a trade-in nets away (a limit B-14 records).
/// one cost account a trade-in nets away (a limit BS-statement-3 records).
#[test]
fn a_trade_in_is_disclosed() {
let mut b = funded();
@@ -2216,7 +2216,7 @@ fn financing_lists_each_members_contributions_and_distributions() {
/// ASC 230-10-45-25 requires interest received (b) and interest paid (e)
/// "at a minimum" apart from the other classes, so an entry's operating
/// cash is classed kind by kind: its interest lines are (b) or (e)
/// whatever else it settles, the rest by its structure (rules.md B-14
/// whatever else it settles, the rest by its structure (BS-statement-3
/// rule 5). By hand:
/// - a payment of 900 on a loan the settings leave operating, with 100
/// interest (Dr 2500 900, Dr 6200 100 / Cr cash 1,000): (d) −900 and
@@ -2547,7 +2547,7 @@ fn a_reversed_bill_payment_leaves_the_purchase_unpaid() {
}
// ---------------------------------------------------------------------------
// Role refusals (rules.md B-14 rule 2) and the footing check (rule 9).
// Role refusals (BS-statement-3 rule 2) and the footing check (rule 9).
// ---------------------------------------------------------------------------
fn refused(b: &Books, cash: &[&str], financing: &[&str], investing: &[&str]) -> String {
@@ -2617,7 +2617,7 @@ fn a_registered_asset_account_cannot_be_cash() {
assert!(m.contains("a registered fixed asset's account"), "{m}");
}
/// rules.md B-14 rule 9: any difference between the sections and the
/// BS-statement-3 rule 9: any difference between the sections and the
/// change in cash is an engine error, never a statement.
#[test]
fn foot_refuses_any_difference() {
@@ -2638,7 +2638,7 @@ fn foot_refuses_any_difference() {
}
// ---------------------------------------------------------------------------
// Properties over random books (rules.md B-14; plan P3: 5,000 cases).
// Properties over random books (BS-statement-3; plan P3: 5,000 cases).
// ---------------------------------------------------------------------------
mod random {
@@ -3011,7 +3011,7 @@ use random::*;
proptest! {
#![proptest_config(ProptestConfig::with_cases(cases()))]
/// rules.md B-14 over random books, reversals of reversals included:
/// BS-statement-3 over random books, reversals of reversals included:
/// 1. the sections sum to the change in cash, which is the model's;
/// 2. each section is its lines and its kinds, and 3. net income and
/// the reconciling items are operating (`foots`);
@@ -3244,7 +3244,7 @@ fn a_disposals_depreciation_credit_back_is_depreciation() {
assert_eq!(cf.cash_from_investing, x("975.00"));
}
/// rules.md B-14 rule 5 (the P3 cutover review's open point 2): ASC
/// BS-statement-3 rule 5 (the P3 cutover review's open point 2): ASC
/// 230-10-45-17(c), "Cash payments to governments for taxes, duties,
/// fines, and other fees or penalties", is not 45-17(b)'s "Cash payments
/// to other suppliers and employees": a state's filing fee booked to an
@@ -3316,7 +3316,7 @@ fn a_payment_to_a_government_is_other_operating() {
assert_eq!((line.class, line.amount), (Some(OtherPayments), x("75.00")));
}
/// rules.md B-14 rule 5: the payee decides on any account, and the tax
/// BS-statement-3 rule 5: the payee decides on any account, and the tax
/// category still does without one: a license on `taxes_licenses` with no
/// party is (g). An entry naming a government and a supplier together
/// (half each) is split by their shares, as ASC 230-10-45-22 has each
@@ -3371,7 +3371,7 @@ fn a_government_payee_moves_a_fee_on_any_account() {
assert_eq!(classes(&cf, shared), [(OtherPayments, x("-100.00"))]);
}
/// rules.md B-14 rule 5: a split by shares that leaves an odd cent rounds
/// BS-statement-3 rule 5: a split by shares that leaves an odd cent rounds
/// the government's part half to even, the supplier's the rest, so the
/// line still sums to the payment; its reversal next month mirrors it to
/// the cent. Fixed amounts split as given.
@@ -3450,7 +3450,7 @@ fn a_shared_government_payment_splits_to_the_cent() {
);
}
/// rules.md B-14 rule 5: a reversal takes its original's payee, so the
/// BS-statement-3 rule 5: a reversal takes its original's payee, so the
/// pair always lands in one class and nets. A state's fee paid in
/// February and reversed in March: (g) both. The books keep a reversal
/// chain's parties one (Ledger::set_entry_parties INVARIANT 5): tagging
@@ -3500,7 +3500,7 @@ fn a_reversal_takes_its_originals_payee() {
assert_eq!(classes(&b), both(ToSuppliersAndEmployees));
}
/// rules.md B-14 rules 5 and 11: a payment shared between a state and an
/// BS-statement-3 rules 5 and 11: a payment shared between a state and an
/// agent that a member paid personally (Dr 6000 137.00 / Cr 2100, the
/// members' financing account) is borrowed and spent, and its spending is
/// split by the parties' shares as a bank payment's is, the part no bank
@@ -3577,7 +3577,7 @@ fn a_shared_government_payment_a_member_paid_splits_both_ways() {
assert_eq!(cf.net_change_in_cash, Decimal::ZERO);
}
/// rules.md B-14 rule 5 (CONVENTION): payroll keeps its structure. Taxes
/// BS-statement-3 rule 5 (CONVENTION): payroll keeps its structure. Taxes
/// withheld from employees and remitted to the tax agency are the
/// employees' pay (45-17(b), "Cash payments to other suppliers and
/// employees"), and the payroll payables mix them with the employer's
@@ -3636,7 +3636,7 @@ fn a_payroll_remittance_to_a_tax_agency_stays_pay() {
assert_eq!(class(employer), Some(OtherPayments));
}
/// rules.md B-14 rule 5: a government selling goods or services is a
/// BS-statement-3 rule 5: a government selling goods or services is a
/// supplier (45-17(b), "for other goods or services"), not 45-17(c)'s
/// taxes, fees or penalties: the post office named with the `vendor`
/// role, postage stays (d). The roles decide, so a post office given the
@@ -3664,7 +3664,7 @@ fn a_government_selling_services_is_a_supplier() {
}
/// A bill whose line is equipment, paid later: the payment's cash is
/// investing, through the bill's split (D-35; rules.md B-14), not
/// investing, through the bill's split (D-35; BS-statement-3), not
/// operating. Plan P4b S6 keeps this true when the bill is paid as part
/// of a settlement.
#[test]
@@ -1,4 +1,4 @@
//! An invoice's or bill's lines name their projects (rules.md B-37 item
//! An invoice's or bill's lines name their projects (BS-statement-5 item
//! 8): the posted entry's revenue or expense side is one line per project,
//! the untagged lines' as one; the receivable or payable line, and the
//! payments, never take one.
@@ -6,9 +6,9 @@
//! ```text
//! GOAL: a client project's invoiced revenue and a contractor's billed
//! cost count toward the project, every other figure as before.
//! SOURCE: docs/spec/rules.md B-37 items 3 and 8 (job costing), B-14 (the
//! projects with the untagged lines partition the P&L), B-19 and
//! B-35 (1099 and party figures follow the money, not the tags).
//! SOURCE: BS-statement-5 items 3 and 8 (job costing), BS-statement-3 (the
//! projects with the untagged lines partition the P&L), BS-1099-1 and
//! BS-partner-3 (1099 and party figures follow the money, not the tags).
//! ```
use chrono::NaiveDate;
@@ -170,7 +170,7 @@ fn a_bills_cost_is_one_line_per_project_and_the_payable_none() {
}
/// Reversing a tagged invoice's or bill's entry carries each line's
/// project to the reversal (B-37 item 3: each line on its normal side), so
/// project to the reversal (BS-statement-5 item 3: each line on its normal side), so
/// every project nets back to zero; a partial payment, cash against the
/// receivable, moves no project figure.
#[test]
@@ -209,7 +209,7 @@ fn reversing_a_tagged_document_takes_its_projects_to_zero() {
.unwrap();
assert_eq!(to_date(&b.l, z), (cents(300_000), cents(120_000)));
assert_eq!(to_date(&b.l, h), (cents(20_000), Decimal::ZERO));
// The payment first: a void waits on the payments that stand (B-38
// The payment first: a void waits on the payments that stand (BS-arap-2
// scenario 3); its reversal moves no project figure either.
b.l.reverse_entry(pay, d(2026, 3, 30), "Bounced").unwrap();
assert_eq!(to_date(&b.l, z), (cents(300_000), cents(120_000)));
@@ -294,7 +294,7 @@ fn a_line_naming_an_unknown_project_is_refused_whole() {
assert!(b.l.differs_from(&before).is_empty(), "nothing changed");
}
/// Finished and abandoned projects still take a document's lines (B-37
/// Finished and abandoned projects still take a document's lines (BS-statement-5
/// item 5: a late cost, a final invoice).
#[test]
fn a_finished_project_still_takes_an_invoice() {
+26 -26
View File
@@ -1,12 +1,12 @@
//! Documents read their figures from the ledger lines tagged with them
//! (rules.md B-38; plan P4b S1, D-45): one test per scenario of the
//! B-38 spec block, then the properties.
//! (BS-arap-2; plan P4b S1, D-45): one test per scenario of the
//! BS-arap-2 spec block, then the properties.
//!
//! ```text
//! GOAL: invoices and bills are the subledgers of the receivables and
//! payables control accounts; every figure about a document is read
//! from the ledger lines tagged with it.
//! SOURCE: docs/spec/rules.md B-8, B-9, B-10, B-18, B-23, B-28, B-38;
//! SOURCE: BS-ledger-4, BS-ledger-5, BS-ledger-6, BS-arap-1, BS-ledger-8, BS-entry-4, BS-arap-2;
//! ASC 310-10, ASC 405-20-40-1, ASC 606-10-45-4.
//! ```
@@ -109,7 +109,7 @@ impl Books {
self.l.chart().find_by_code(code).unwrap().id
}
/// Every control account's tie-out holds: no difference (B-38
/// Every control account's tie-out holds: no difference (BS-arap-2
/// INVARIANT 1).
fn ties(&self, on: NaiveDate) {
for c in self.l.control_check(on).unwrap() {
@@ -186,7 +186,7 @@ fn a_voided_invoice_never_ages() {
Err(LedgerError::InvalidVoid(why)) => assert!(why.contains(&r.to_string()), "{why}"),
other => panic!("expected InvalidVoid, got {other:?}"),
}
// Reversing the void re-instates it (B-10); voiding again reverses
// Reversing the void re-instates it (BS-ledger-6); voiding again reverses
// that reversal, the end of the chain.
let back = b.l.reverse_entry(r, d(2026, 2, 7), "Re-instate").unwrap();
assert_eq!(
@@ -500,7 +500,7 @@ fn deposit_account_must_be_cash_like() {
}
/// A reversal of an entry a document owns is never dated before it
/// (B-9; P4b.3, "Dating rules").
/// (BS-ledger-5; P4b.3, "Dating rules").
#[test]
fn reversal_before_original_refused_for_documents() {
let mut b = books();
@@ -1067,7 +1067,7 @@ fn out_of_bounds_documents_are_listed_not_aged() {
/// Reversing a legacy hand line takes it off; reversing that reversal
/// would put it back, and is refused: no command adds an untagged control
/// line (B-38 INVARIANT 1 and item 3; first review of S1).
/// line (BS-arap-2 INVARIANT 1 and item 3; first review of S1).
#[test]
fn putting_back_a_removed_hand_line_is_refused() {
let mut b = books();
@@ -1201,10 +1201,10 @@ fn a_chain_counts_in_order() {
}
// ---------------------------------------------------------------------------
// Write-offs (plan P4b S7; rules.md B-41)
// Write-offs (plan P4b S7; BS-arap-5)
// ---------------------------------------------------------------------------
/// B-38 SCENARIO 7 and B-41 INVARIANT 1: half of an invoice paid, the rest
/// BS-arap-2 SCENARIO 7 and BS-arap-5 INVARIANT 1: half of an invoice paid, the rest
/// written off, reads Written off with 50 paid and 50 written off, and
/// receivables falls by the write-off alone.
#[test]
@@ -1261,7 +1261,7 @@ fn half_paid_rest_written_off_is_written_off() {
assert!(check.iter().all(|c| c.difference.is_zero()));
}
/// B-41 INVARIANT 3: a cash-basis company never counted the invoice as
/// BS-arap-5 INVARIANT 3: a cash-basis company never counted the invoice as
/// income, so it has no basis to deduct (IRC §166; Treas. Reg.
/// §1.166-1(e)).
#[test]
@@ -1308,7 +1308,7 @@ fn write_off_refused_on_cash_basis() {
);
}
/// B-41 INVARIANT 1: at most what is owed, a partial write-off allowed
/// BS-arap-5 INVARIANT 1: at most what is owed, a partial write-off allowed
/// (Treas. Reg. §1.166-3(a)); more is refused, naming what is owed, and
/// nothing changes.
#[test]
@@ -1351,7 +1351,7 @@ fn write_off_above_outstanding_refused() {
assert_eq!((st.paid, st.written_off), (cents(4_000), cents(6_000)));
}
/// D-49's same-year recovery, and B-41 INVARIANT 2: reversing the
/// D-49's same-year recovery, and BS-arap-5 INVARIANT 2: reversing the
/// write-off re-instates the debt (it is not a new movement), and the
/// payment then recorded settles it; a recovery is income, never a
/// payment event.
@@ -1502,7 +1502,7 @@ fn days(b: &Books) -> Vec<NaiveDate> {
proptest! {
#![proptest_config(ProptestConfig::with_cases(256))]
/// B-38 INVARIANTS 1, 2 and 6 over random histories of creates,
/// BS-arap-2 INVARIANTS 1, 2 and 6 over random histories of creates,
/// payments, voids, reversals of any entry and refused hand lines: at
/// every date the control accounts equal their documents (no
/// difference, nothing unattached: no command adds a hand line), each
@@ -1538,7 +1538,7 @@ proptest! {
}
}
/// B-38 INVARIANT 5: the aging as of a day partitions what the
/// BS-arap-2 INVARIANT 5: the aging as of a day partitions what the
/// documents owe then (in books these commands write, none owes less
/// than nothing). INVARIANT 4 (Store, replay and Snapshot agree) is
/// ledger-store's `status_is_a_function_of_journal_and_date`.
@@ -1562,7 +1562,7 @@ proptest! {
}
}
/// B-38 INVARIANT 3: reversing a tagged entry moves its documents by
/// BS-arap-2 INVARIANT 3: reversing a tagged entry moves its documents by
/// exactly the opposite of the entry's own tagged lines from the
/// reversal's day (read from the entry reversed, not from the mirror,
/// so a mirror that lost its tag is caught); reversing that reversal
@@ -1637,7 +1637,7 @@ fn doc_line(
}
}
/// B-39 SCENARIOS: Net 30, Net 15 EOM, a leap day, due on receipt, a
/// BS-arap-3 SCENARIOS: Net 30, Net 15 EOM, a leap day, due on receipt, a
/// custom date, and the 9999-12 bound refused instead of panicking.
#[test]
fn terms_derive_due_dates() {
@@ -1671,7 +1671,7 @@ fn terms_derive_due_dates() {
assert!(Terms::new(TermsKind::NetEom(3_651), None).is_err());
}
/// B-39 INVARIANT 2: the discount's bound, its date, and the terms that
/// BS-arap-3 INVARIANT 2: the discount's bound, its date, and the terms that
/// cannot carry one.
#[test]
fn discount_bounds_and_late_reason() {
@@ -1741,7 +1741,7 @@ fn discount_bounds_and_late_reason() {
assert_eq!(kernel::discount_max(cents(-1), 200), None);
}
/// B-39 INVARIANT 3: the canonical spellings read back as they print.
/// BS-arap-3 INVARIANT 3: the canonical spellings read back as they print.
#[test]
fn terms_describe_and_parse_round_trip() {
for text in [
@@ -1899,7 +1899,7 @@ fn qty_times_price_must_equal_amount() {
));
}
/// B-39 line accounts: an invoice takes revenue or deferred revenue; a
/// BS-arap-3 line accounts: an invoice takes revenue or deferred revenue; a
/// bill takes an expense or a non-cash asset; roles, cash and headers are
/// refused (plan P4b S4.1, A-10).
#[test]
@@ -1959,7 +1959,7 @@ fn document_line_account_refuses_roles_cash_and_placeholders() {
assert_eq!(b.l.next_bill_id(), before);
}
/// A-2, B-40: numbers run, a void keeps its number, legacy invoices are
/// A-2, BS-arap-4: numbers run, a void keeps its number, legacy invoices are
/// not counted, and a number is never reused.
#[test]
fn numbers_run_and_voids_keep_theirs() {
@@ -2033,7 +2033,7 @@ fn numbers_run_and_voids_keep_theirs() {
);
}
/// B-40: four digits, wider past 9,999, never truncated.
/// BS-arap-4: four digits, wider past 9,999, never truncated.
#[test]
fn number_widens_past_9999() {
let mut b = books();
@@ -2053,7 +2053,7 @@ fn number_widens_past_9999() {
assert_eq!(b.l.next_invoice_number("INV-", 9_999), "INV-10000");
}
/// B-40: a vendor's invoice number names one standing bill; case, spaces
/// BS-arap-4: a vendor's invoice number names one standing bill; case, spaces
/// and hyphens are ignored; a duplicate needs a reason (plan P4b S4.1).
#[test]
fn duplicate_vendor_ref_refused_unless_a_reason_is_given() {
@@ -2124,13 +2124,13 @@ fn duplicate_vendor_ref_refused_unless_a_reason_is_given() {
}
// ---------------------------------------------------------------------------
// P4b S6: paying on terms (rules.md B-42)
// P4b S6: paying on terms (BS-arap-6)
// ---------------------------------------------------------------------------
/// A bill on "2/10 net 30", paid within the discount window: the gross
/// method's entry is Dr A/P the full amount, Cr purchase discounts what
/// was taken, Cr the bank the rest; the bill reads paid and discounted.
/// A discount larger than the terms allow needs a reason (B-42).
/// A discount larger than the terms allow needs a reason (BS-arap-6).
#[test]
fn bill_on_terms_with_discount() {
use ledger_core::{Application, DocRef, SettleParams};
@@ -2231,7 +2231,7 @@ fn bill_on_terms_with_discount() {
.unwrap();
}
/// A discount taken after the discount date needs a reason (B-42
/// A discount taken after the discount date needs a reason (BS-arap-6
/// INVARIANT 2); a bill with an asset or prepaid line refuses one with the
/// D-49 remedy, and none of the refusals changes the books.
#[test]
@@ -2379,7 +2379,7 @@ fn a_fee_posts_gross_to_receivables_and_net_to_the_bank() {
/// A payment that settles more than one document names its lines in
/// application order, and two applications on one document are refused:
/// each document's bound is one bound (B-42 INVARIANTS 1 and 2).
/// each document's bound is one bound (BS-arap-6 INVARIANTS 1 and 2).
#[test]
fn a_settlement_names_its_lines_and_refuses_a_document_twice() {
use ledger_core::{Application, DocRef, SettleParams};
+39 -39
View File
@@ -130,7 +130,7 @@ fn try_post(
}
/// [`try_post`] through the replay path, which books written before the
/// minor-unit rule (B-3, 2026-10-13) still take: for the kernel's own
/// minor-unit rule (BS-ledger-1, 2026-10-13) still take: for the kernel's own
/// limits below a cent.
fn try_replay_post(
l: &mut Ledger,
@@ -245,7 +245,7 @@ fn tb_has_code(l: &Ledger, as_of: NaiveDate, code: &str) -> bool {
// add_account
// ---------------------------------------------------------------------------
/// Oracle: R-4 / B-4: an added account is findable by its code with exactly
/// Oracle: R-4 / BS-ledger-2: an added account is findable by its code with exactly
/// the type, parent, and placeholder flag it was given.
#[test]
fn an_added_account_is_registered_under_its_code() {
@@ -339,7 +339,7 @@ fn a_refused_account_never_uses_up_an_id() {
assert_eq!(id, announced);
}
/// Oracle: add_account SCENARIO 3 (B-4 DECISION): a child of another type is
/// Oracle: add_account SCENARIO 3 (BS-ledger-2 DECISION): a child of another type is
/// refused with ParentTypeMismatch and NEVER added.
#[test]
fn a_child_account_has_its_parents_type() {
@@ -390,7 +390,7 @@ fn a_new_draft_gets_the_next_id_one_past_the_last() {
assert!(e.lines().is_empty());
}
/// Oracle: try_create_entry SCENARIO 1 (B-12): a date inside a closed period,
/// Oracle: try_create_entry SCENARIO 1 (BS-period-2): a date inside a closed period,
/// first and last day included, is refused with ClosedPeriod and creates
/// nothing; the day after the period is accepted.
#[test]
@@ -444,7 +444,7 @@ fn lines_are_kept_in_the_order_added() {
);
}
/// Oracle: B-1 DECISION (owner, 2026-10-13): a line on an unknown account
/// Oracle: BS-entry-1 DECISION (owner, 2026-10-13): a line on an unknown account
/// is refused when added (UnknownAccount), not only at post.
#[test]
fn a_line_on_an_unknown_account_is_refused_when_added() {
@@ -458,7 +458,7 @@ fn a_line_on_an_unknown_account_is_refused_when_added() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: B-1 DECISION / R-4: a line on a placeholder account is refused
/// Oracle: BS-entry-1 DECISION / R-4: a line on a placeholder account is refused
/// when added (PlaceholderAccount).
#[test]
fn a_line_on_a_placeholder_account_is_refused_when_added() {
@@ -473,7 +473,7 @@ fn a_line_on_a_placeholder_account_is_refused_when_added() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: B-3 / R-5 and the add_line doc: a foreign-currency amount is
/// Oracle: BS-ledger-1 / R-5 and the add_line doc: a foreign-currency amount is
/// refused, never converted (CurrencyMismatch).
#[test]
fn a_foreign_currency_line_is_refused_not_converted() {
@@ -493,7 +493,7 @@ fn a_foreign_currency_line_is_refused_not_converted() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: R-3 / B-8 and the PostedEntryImmutable doc ("add lines"): a posted
/// Oracle: R-3 / BS-ledger-4 and the PostedEntryImmutable doc ("add lines"): a posted
/// entry takes no more lines.
#[test]
fn a_posted_entry_takes_no_more_lines() {
@@ -523,7 +523,7 @@ fn a_line_on_an_unknown_entry_is_refused() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: B-3 (ASC 830-20-30-1) and the add_line_fx doc: base = foreign ×
/// Oracle: BS-ledger-1 (ASC 830-20-30-1) and the add_line_fx doc: base = foreign ×
/// rate (100 EUR × 1.10 = 110.00 USD), the original kept; the entry then
/// balances in base currency.
#[test]
@@ -569,7 +569,7 @@ fn a_non_positive_fx_rate_is_refused() {
}
}
/// Oracle: rules.md B-3 "Checked: fx_overflow_is_an_error" and B-21 (exact
/// Oracle: BS-ledger-1 "Checked: fx_overflow_is_an_error" and BS-entry-3 (exact
/// amounts): a product that can't be represented is refused, never rounded
/// or wrapped.
#[test]
@@ -584,7 +584,7 @@ fn fx_overflow_is_an_error() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: B-1 DECISION applies to add_line_fx too: unknown account refused
/// Oracle: BS-entry-1 DECISION applies to add_line_fx too: unknown account refused
/// when added.
#[test]
fn a_foreign_line_on_an_unknown_account_is_refused_when_added() {
@@ -598,7 +598,7 @@ fn a_foreign_line_on_an_unknown_account_is_refused_when_added() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: B-3 + line range (AmountOutOfRange: at most one quadrillion):
/// Oracle: BS-ledger-1 + line range (AmountOutOfRange: at most one quadrillion):
/// a foreign line converting to 2,000,000,000,000,000 USD never posts.
#[test]
fn a_foreign_line_beyond_line_range_never_posts() {
@@ -631,7 +631,7 @@ fn posting_an_unknown_entry_is_refused() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: post_entry SCENARIO 2 (B-8): a posted entry is never posted
/// Oracle: post_entry SCENARIO 2 (BS-ledger-4): a posted entry is never posted
/// twice (EntryAlreadyPosted), the log unchanged.
#[test]
fn a_posted_entry_is_never_posted_twice() {
@@ -647,7 +647,7 @@ fn a_posted_entry_is_never_posted_twice() {
assert_eq!(b.l.posted_entries().count(), 1);
}
/// Oracle: post_entry SCENARIO 3 (B-12): an entry dated in a closed period
/// Oracle: post_entry SCENARIO 3 (BS-period-2): an entry dated in a closed period
/// is refused (ClosedPeriod), even one drafted through the unchecked
/// constructor.
#[test]
@@ -670,7 +670,7 @@ fn an_entry_dated_in_a_closed_period_never_posts() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: R-1/B-1: fewer than two lines is refused (TooFewLines), for zero
/// Oracle: R-1/BS-entry-1: fewer than two lines is refused (TooFewLines), for zero
/// lines and for one.
#[test]
fn an_entry_with_fewer_than_two_lines_never_posts() {
@@ -690,7 +690,7 @@ fn an_entry_with_fewer_than_two_lines_never_posts() {
assert_eq!(b.l.posted_entries().count(), 0);
}
/// Oracle: R-1/B-1 (no epsilon): 100.00 against 99.99 is refused with the
/// Oracle: R-1/BS-entry-1 (no epsilon): 100.00 against 99.99 is refused with the
/// offending totals.
#[test]
fn an_unbalanced_entry_is_refused_with_its_totals() {
@@ -744,7 +744,7 @@ fn exact_decimal_sums_balance() {
assert_eq!(r, None);
}
/// Oracle: R-6 / B-2: a zero-amount line is refused (ZeroAmountLine).
/// Oracle: R-6 / BS-entry-2: a zero-amount line is refused (ZeroAmountLine).
#[test]
fn a_zero_amount_line_never_posts() {
let mut b = books();
@@ -761,7 +761,7 @@ fn a_zero_amount_line_never_posts() {
assert_eq!(b.l.posted_entries().count(), 0);
}
/// Oracle: B-2: a negative amount is refused (NegativeAmountLine): the side
/// Oracle: BS-entry-2: a negative amount is refused (NegativeAmountLine): the side
/// says the direction.
#[test]
fn a_negative_amount_line_never_posts() {
@@ -799,7 +799,7 @@ fn line_range_is_one_quadrillion_and_ten_places() {
ok(&mut b, "1000000000000000.01"),
Some(LedgerError::AmountOutOfRange)
);
// Below a cent, new work is refused first (B-3); replayed books meet
// Below a cent, new work is refused first (BS-ledger-1); replayed books meet
// the kernel's ten-place limit.
assert!(matches!(
ok(&mut b, "0.0000000001"),
@@ -886,7 +886,7 @@ fn the_log_is_in_posting_order() {
// check_reversal / reverse_entry
// ---------------------------------------------------------------------------
/// Oracle: B-9 (Pacioli's storno): the reversal has the same lines with
/// Oracle: BS-ledger-5 (Pacioli's storno): the reversal has the same lines with
/// sides flipped, is posted, dated as asked, linked by `reversal_of`, and
/// returns every balance to what it was.
#[test]
@@ -917,12 +917,12 @@ fn a_reversal_mirrors_the_original_and_cancels_it() {
for a in [b.exp, b.cash, b.card] {
assert_eq!(b.l.account_balance(a).unwrap(), Decimal::ZERO);
}
// The original is untouched (B-8): never erased.
// The original is untouched (BS-ledger-4): never erased.
assert_eq!(b.l.get_entry(e).unwrap().status(), EntryStatus::Posted);
assert_eq!(b.l.posted_entries().count(), 2);
}
/// Oracle: B-10 / check_reversal SCENARIO 2: an entry is reversed at most
/// Oracle: BS-ledger-6 / check_reversal SCENARIO 2: an entry is reversed at most
/// once (EntryAlreadyReversed(entry, by)); reversing the reversal is allowed
/// and re-instates it, and does not reopen the original.
#[test]
@@ -986,7 +986,7 @@ fn only_posted_entries_are_reversed() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: B-10 / check_reversal SCENARIO 3: a closing entry is never
/// Oracle: BS-ledger-6 / check_reversal SCENARIO 3: a closing entry is never
/// reversed (ClosingEntryIrreversible), even dated in an open period.
#[test]
fn a_closing_entry_is_never_reversed() {
@@ -1015,7 +1015,7 @@ fn a_closing_entry_is_never_reversed() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: check_reversal SCENARIO 4 (B-12): a reversal dated in a closed
/// Oracle: check_reversal SCENARIO 4 (BS-period-2): a reversal dated in a closed
/// period is refused (ClosedPeriod); dated after it, accepted.
#[test]
fn a_reversal_is_never_dated_in_a_closed_period() {
@@ -1184,7 +1184,7 @@ fn assert_balanced(l: &Ledger, id: EntryId) {
assert_eq!(dr, cr, "closing entry must balance");
}
/// Oracle: close INVARIANTS 1-3 and B-11: closing to retained earnings
/// Oracle: close INVARIANTS 1-3 and BS-period-1: closing to retained earnings
/// zeroes revenue and expense as of Jan 31, credits 3999 (created, equity)
/// with exactly the net 700.00, is dated Jan 31, balances, locks the
/// period, and leaves February's 50.00 sale untouched.
@@ -1296,7 +1296,7 @@ fn a_period_with_drafts_never_closes() {
assert_eq!(observe(&b.l), before);
}
/// Oracle: close SCENARIO 3 (B-12): closing out of order is refused
/// Oracle: close SCENARIO 3 (BS-period-2): closing out of order is refused
/// (CloseOutOfOrder(id, later)).
#[test]
fn periods_close_in_order() {
@@ -1443,7 +1443,7 @@ fn members(shares: &[(AccountId, &str, Option<AccountId>)]) -> CloseTo {
)
}
/// Oracle: B-13 / AGENTS.md (50/50): net 700.00 splits 350.00 / 350.00; each
/// Oracle: BS-partner-1 / AGENTS.md (50/50): net 700.00 splits 350.00 / 350.00; each
/// member's distributions close into their own capital.
#[test]
fn a_partnership_close_splits_by_share() {
@@ -1488,7 +1488,7 @@ fn net_books(net: &str) -> (Books, PeriodId, AccountId) {
(b, jan, cap_c)
}
/// Oracle: B-13 DECISION (largest remainder, ties to the earlier member),
/// Oracle: BS-partner-1 DECISION (largest remainder, ties to the earlier member),
/// hand-computed: 1.05 at 0.3/0.3/0.4 is exactly 0.315/0.315/0.42; rounded
/// down 0.31/0.31/0.42 leaves one cent, remainders .005/.005/0 tie, so the
/// first member gets it: 0.32/0.31/0.42. (The retired last-absorbs rule
@@ -1507,7 +1507,7 @@ fn members_split_by_largest_remainder_ties_to_the_earlier() {
assert_eq!(b.l.account_balance(cap_c).unwrap(), dec("0.42"));
}
/// Oracle: B-13 / kernel::apportion INVARIANT 3, hand-computed: 0.07 at
/// Oracle: BS-partner-1 / kernel::apportion INVARIANT 3, hand-computed: 0.07 at
/// 0.2/0.3/0.5 is exactly 0.014/0.021/0.035; rounded down 0.01/0.02/0.03
/// (sum 0.06), remainders .004/.001/.005, so the largest remainder (the
/// third) gets the cent: 0.01/0.02/0.04, wherever it sits in the list.
@@ -1736,7 +1736,7 @@ fn only_a_posted_line_can_clear() {
// account_balance
// ---------------------------------------------------------------------------
/// Oracle: account_balance INVARIANT 1 / B-5 and trial balance SCENARIO 2:
/// Oracle: account_balance INVARIANT 1 / BS-ledger-3 and trial balance SCENARIO 2:
/// asset debited 100 and credited 30 is 70; credit-normal accounts read
/// credits minus debits; a contra balance is negative.
#[test]
@@ -1818,7 +1818,7 @@ fn the_balance_of_an_unknown_account_is_refused() {
// ---------------------------------------------------------------------------
/// Oracle: set_line_class GOAL: a draft line is tagged (and cleared with
/// None); SCENARIO 1 (B-8): a posted line NEVER changes; SCENARIO 2: an
/// None); SCENARIO 1 (BS-ledger-4): a posted line NEVER changes; SCENARIO 2: an
/// unknown line or class is refused.
#[test]
fn only_draft_lines_take_a_class() {
@@ -2287,7 +2287,7 @@ proptest! {
prop_assert_eq!(observe_but_account_ids(&f.b.l), before, "command {} changed the books ({:?})", k, r);
}
/// Oracle: B-1/B-6 and post_entry INVARIANT 2 against the test's own
/// Oracle: BS-entry-1/BS-statement-1 and post_entry INVARIANT 2 against the test's own
/// model: every balanced random entry posts, the log is exactly the
/// posting sequence, earlier entries never change, every balance equals
/// the model on its normal side, and the trial balance balances.
@@ -2314,7 +2314,7 @@ proptest! {
prop_assert!(trial_balance(&b.l).balanced());
}
/// Oracle: close INVARIANTS 1-4 and B-13 against the test's own model,
/// Oracle: close INVARIANTS 1-4 and BS-partner-1 against the test's own model,
/// for random books closed 50/50 to members at Jan 31: revenue and
/// expense are zero as of Jan 31; what remains is exactly February and
/// March; the members' credits sum to January's net with A taking the
@@ -2551,7 +2551,7 @@ fn renumber_refusals_leave_the_books_unchanged() {
}
// ---------------------------------------------------------------------
// Ledger::rename_account (P3, defect 15; rules.md B-31).
// Ledger::rename_account (P3, defect 15; BS-ledger-10).
// ---------------------------------------------------------------------
proptest! {
@@ -2721,7 +2721,7 @@ fn a_closed_period_or_a_role_never_blocks_a_rename() {
assert_eq!(l.role_account(&ledger_core::GENERAL_EXPENSES), Some(b.exp));
}
/// rename_account INVARIANT 3 (rules.md B-28's pair): replay takes a
/// rename_account INVARIANT 3 (BS-entry-4's pair): replay takes a
/// journaled name the command now refuses (blank, a sibling's, nine
/// digits, unchanged) for an account that exists, and refuses only an
/// unknown account.
@@ -2738,7 +2738,7 @@ fn a_journaled_rename_replays_past_the_command_rules() {
);
}
/// add_account SCENARIOS 5-6 (rules.md B-31): a new account named like a
/// add_account SCENARIOS 5-6 (BS-ledger-10): a new account named like a
/// sibling (ignoring capitals and surrounding space; top-level accounts
/// are siblings) or holding a run of nine digits is refused, using up no
/// id; under another parent the name is free. Replay takes them all, and
@@ -2838,12 +2838,12 @@ fn a_rename_reason_is_bounded_text_without_a_tin() {
assert!(Ledger::check_rename_reason(&"x".repeat(2_000)).is_ok());
}
/// add_account SCENARIOS 7-8 and rename_account SCENARIO 6 (rules.md
/// B-31): a new name is one line of at most MAX_ACCOUNT_NAME characters,
/// add_account SCENARIOS 7-8 and rename_account SCENARIO 6 (
/// BS-ledger-10): a new name is one line of at most MAX_ACCOUNT_NAME characters,
/// kept trimmed, by a new account and a rename alike: 200 characters are
/// taken, 201 refused, and so is a line break, a tab or another control
/// character; surrounding space is dropped the same way on both paths.
/// Replay takes any journaled name (B-28).
/// Replay takes any journaled name (BS-entry-4).
#[test]
fn a_new_name_is_one_trimmed_line_of_bounded_length() {
use ledger_core::account::MAX_ACCOUNT_NAME;
+4 -4
View File
@@ -232,7 +232,7 @@ fn redact_full_tins_masks_every_full_tin() {
}
/// Oracle: `check_text` refuses what `has_full_tin` finds, so a purge
/// reason or note quoting the old number with dots is refused (B-26: no
/// reason or note quoting the old number with dots is refused (BS-partner-2: no
/// party field may hold a nine-digit number).
#[test]
fn check_text_refuses_a_dotted_tin() {
@@ -1461,7 +1461,7 @@ fn entry_flow_takes_across_in_order_until_used_up() {
);
}
/// Oracle: shares::target DEFINITIONS, case 3 (rules.md B-35): members
/// Oracle: shares::target DEFINITIONS, case 3 (BS-partner-3): members
/// named on an entry moving no money split what moved equity, E (here
/// −4.00 of a draft not yet balanced), received, in kind (the equipment's
/// 10.00, at most |E|); case 5: with a party named who isn't a member,
@@ -1860,7 +1860,7 @@ mod shares {
assert_eq!(paid_received(&b, b.mo), (Decimal::ZERO, d("100.00")));
}
/// SCENARIO 3 (defect 14, rules.md B-35): property contributed moves
/// SCENARIO 3 (defect 14, BS-partner-3): property contributed moves
/// no money; each member's part is what moved their capital, signed
/// as their own account shows it: received, in kind. Basis cash
/// counts nothing; basis all counts it. (Before P3 this read +500.00
@@ -1919,7 +1919,7 @@ mod shares {
assert_eq!((a.paid, a.received), (Decimal::ZERO, Decimal::ZERO));
}
/// rules.md B-35 item 3 (capital first): a members' entry counts what
/// BS-partner-3 item 3 (capital first): a members' entry counts what
/// moved their capital, not other money on it: 300.00 in, 200.00 of it
/// Tobin's capital and 100.00 an expense refunded, is Tobin's 200.00
/// received (cash) and nothing of Morgan's. (Before P3 the 300.00 net
+17 -17
View File
@@ -1,13 +1,13 @@
//! P3 defects 14, 24 and 11: a party's part of an entry, a party's
//! totals, and the directory's TIN last four.
//!
//! Oracles: rules.md B-35 (a party's part, signed as a line on its own
//! Oracles: BS-partner-3 (a party's part, signed as a line on its own
//! account, with its direction and its money and property; party totals
//! on basis cash or all; a member's entry counts what moved their capital;
//! money is cash, cards, the members' financing and loans; a liability
//! credit never counts as paying that liability's own creditor), B-9 (a
//! correction is the opposite entry), B-13 and the K-1 worksheet (k1
//! INVARIANT 3: what is property), B-26 (a TIN's last four), and the spec
//! credit never counts as paying that liability's own creditor), BS-ledger-5 (a
//! correction is the opposite entry), BS-partner-1 and the K-1 worksheet (k1
//! INVARIANT 3: what is property), BS-partner-2 (a TIN's last four), and the spec
//! blocks of `ledger_core::shares`, `ledger_core::parties` (`flow`,
//! `activity_with`, `Party::tin_last4`) and `ledger_core::kernel`
//! (`party_target`, `reverse_target`). Every expected value is worked by
@@ -257,7 +257,7 @@ fn part(party: PartyId, amount: &str, cash: &str, in_kind: &str) -> Part {
use Side::{Credit as Cr, Debit as Dr};
/// The audit's reproduction (F36, F37), anonymized, with what each row
/// should say (rules.md B-35): `resolved` signed as a line on the party's
/// should say (BS-partner-3): `resolved` signed as a line on the party's
/// own account, a direction, and what of it was money or property; a
/// reversal the exact opposite of what it reverses; totals on both bases,
/// labelled.
@@ -550,7 +550,7 @@ fn defect14_shares_take_the_partys_side_and_reversals_flip() {
);
}
/// B-35 item 4: on the member-only entries, basis all is the statement of
/// BS-partner-3 item 4: on the member-only entries, basis all is the statement of
/// members' equity (contributions and distributions, the same dates), and
/// basis cash is the K-1 worksheet's cash contributions.
#[test]
@@ -655,7 +655,7 @@ fn defect24_an_accrual_through_another_liability_counts_once() {
assert_eq!(b.totals(c, Basis::All), (Decimal::ZERO, d("1200.00")));
}
/// Defect 24 and B-35 item 6: a credit to what the company owes a party
/// Defect 24 and BS-partner-3 item 6: a credit to what the company owes a party
/// itself never counts as paying it. A fee on the issuer's own card is a
/// bill from the issuer (counted when the card is paid); a distribution
/// still owed to a member counts when it is paid; equipment bought on the
@@ -749,7 +749,7 @@ fn defect24_a_credit_to_a_partys_own_liability_never_pays_it() {
assert_eq!(b.totals(m, Basis::All), (Decimal::ZERO, d("800.00")));
}
/// The known limit B-35 states (and the tool text says): when the
/// The known limit BS-partner-3 states (and the tool text says): when the
/// members aren't named the creditors of their financing account, a
/// distribution declared through it counts when declared and again when
/// paid. Pinned so a change to it is seen.
@@ -778,7 +778,7 @@ fn a_distribution_owed_counts_twice_until_the_members_are_named_its_creditors()
/// again when paid (400.00); now it counts nothing until it is paid, then
/// 200.00, once, on both bases (Helvering v. Price; party_target
/// INVARIANT 2). The statement of members' equity counts it when declared:
/// party totals catch up when it is paid (B-35 item 4's conditions).
/// party totals catch up when it is paid (BS-partner-3 item 4's conditions).
#[test]
fn defect24_a_distribution_declared_to_a_payable_counts_once_when_paid() {
let mut b = books();
@@ -829,7 +829,7 @@ fn defect24_a_distribution_declared_to_a_payable_counts_once_when_paid() {
assert_eq!(b.totals(t, Basis::Cash), (d("300.00"), Decimal::ZERO));
}
/// B-35 item 3: a distribution's cash is the money it paid and its in
/// BS-partner-3 item 3: a distribution's cash is the money it paid and its in
/// kind the property it gave. Equipment carried at 1,000.00 less 300.00
/// depreciated, and 100.00 in cash, distributed: 100.00 cash and 700.00
/// in kind (it read 800.00 in kind and no cash, the equipment's cost
@@ -868,7 +868,7 @@ fn a_distribution_of_money_and_depreciated_property_splits_by_what_moved() {
assert_eq!(b.resolved(gain).1, vec![part(t, "900.00", "0", "900.00")]);
}
/// Defect 24 and the card rule (B-35 item 5): a gift card the company
/// Defect 24 and the card rule (BS-partner-3 item 5): a gift card the company
/// sold is deferred revenue, a promise, though its account's name says
/// "card". It counted as received when sold and again when redeemed
/// (200.00); now once, when the money came in. A card the company pays
@@ -892,7 +892,7 @@ fn defect24_a_gift_card_sold_is_received_once() {
assert_eq!(b.totals(c, Basis::All), (Decimal::ZERO, d("100.00")));
}
/// B-35 item 5 and `parties::card_accounts` INVARIANTS 1-4: one rule for
/// BS-partner-3 item 5 and `parties::card_accounts` INVARIANTS 1-4: one rule for
/// what a card is. Before any business card is recorded, the liabilities
/// whose names say "card" but not "gift" (2050 Business Card; never 2410
/// Gift Card Liability), less a member's card's account; once one is
@@ -958,7 +958,7 @@ fn a_card_is_a_recorded_business_card_else_a_liability_named_card() {
assert_eq!(b.resolved(on_2050).0.direction, Direction::Neither);
}
/// B-35 item 3, case 3: E is the movement of equity other than retained
/// BS-partner-3 item 3, case 3: E is the movement of equity other than retained
/// earnings, so a members' entry reads as the statement of members' equity
/// reads it. Retained earnings given up for equipment moves no member's
/// capital: neither, as the statement shows no distribution. Retained
@@ -1035,7 +1035,7 @@ fn a_refund_is_received_from_the_vendor() {
assert_eq!(b.totals(v, Basis::Cash), (d("100.00"), d("20.00")));
}
/// B-35 item 3 (capital first): a mixed contribution is split into money
/// BS-partner-3 item 3 (capital first): a mixed contribution is split into money
/// and property exactly as the K-1 worksheet splits it (its SCENARIO 3),
/// whichever member the shares list first; an expense a member pays
/// straight to capital is cash, as on the K-1 (k1 INVARIANT 3); a debt
@@ -1168,7 +1168,7 @@ fn a_members_entry_keeps_its_reading_after_they_leave() {
);
}
/// B-35 item 3, case 1: a period's closing entry moves nothing with
/// BS-partner-3 item 3, case 1: a period's closing entry moves nothing with
/// anyone: direction neither, its members' part their income allocated
/// (credited to their capital: negative), counted in no total.
#[test]
@@ -1343,7 +1343,7 @@ fn defect11_a_partys_tin_last4_is_its_tin_facts_else_its_w9s() {
assert_eq!(by_hand.tin_last4(), None);
}
/// The kernel's B-35 cases, by hand (party_target INVARIANTS 1-6) and
/// The kernel's BS-partner-3 cases, by hand (party_target INVARIANTS 1-6) and
/// reverse_target an involution.
#[test]
fn party_target_cases_by_hand() {
@@ -1661,7 +1661,7 @@ proptest! {
/// account converted to capital, some through their distributions
/// accounts, some declared to distributions payable and paid later,
/// and reverse some of it later in the year. For each member, over
/// every span from the year's start to any date (B-35 item 4's
/// every span from the year's start to any date (BS-partner-3 item 4's
/// conditions hold: a reversal in such a span always has its original
/// in it): basis all is the statement of members' equity's
/// contributions and distributions, but for a distribution declared
+6 -6
View File
@@ -1,11 +1,11 @@
//! Projects (rules.md B-37): a class with its facts; its figures are the
//! Projects (BS-statement-5): a class with its facts; its figures are the
//! revenue and expense lines tagged to it.
//!
//! ```text
//! GOAL: a project's record holds only what its rules allow, and its
//! figures are exactly its tagged lines, from one function.
//! SOURCE: docs/spec/rules.md B-37 (job costing; ASC 450-30-25-1 and
//! 340-40-25-5 for on-spec work), B-11 (closes left out).
//! SOURCE: BS-statement-5 (job costing; ASC 450-30-25-1 and
//! 340-40-25-5 for on-spec work), BS-period-1 (closes left out).
//! ```
use chrono::NaiveDate;
@@ -534,7 +534,7 @@ fn a_reversal_nets_a_project_to_zero() {
let entries = project_entries(&b.l, c);
assert_eq!(entries, vec![(r, cents(180_000)), (e, cents(-180_000))]);
// Nothing left on an account, but two lines tagged: it breaks even,
// it isn't untagged (rules.md B-37 item 7).
// it isn't untagged (BS-statement-5 item 7).
assert!(t.expenses_by_account.is_empty());
assert_eq!((t.revenue_lines, t.expenses_lines), (0, 2));
assert!(t.any_tagged());
@@ -652,7 +652,7 @@ fn differs_from_names_projects() {
assert_eq!(a.l.differs_from(&before), vec!["projects"]);
}
/// rules.md B-37 item 7: the margin is the contribution's share of
/// BS-statement-5 item 7: the margin is the contribution's share of
/// revenue, one place, half to even, and none without revenue.
#[test]
fn contribution_margin_is_one_place_and_none_without_revenue() {
@@ -671,7 +671,7 @@ fn contribution_margin_is_one_place_and_none_without_revenue() {
assert_eq!(pct(Decimal::MAX, cents(1)), None, "never panics");
}
/// rules.md B-37 item 7: each month's net to date opens on the lines
/// BS-statement-5 item 7: each month's net to date opens on the lines
/// before the months (a deposit last year) and ends on the net to date;
/// a reimbursement credited above its cost leaves the expense below zero.
#[test]
@@ -1,6 +1,6 @@
//! Figures derived from what replay accepts: computed exactly where exact
//! arithmetic and chrono's calendar reach, refused (TooLargeToCompute,
//! DateOutOfRange) where they don't, never a panic (rules.md B-28; P0
//! DateOutOfRange) where they don't, never a panic (BS-entry-4; P0
//! review round 4, 2026-10-17).
//!
//! ```text
@@ -243,8 +243,8 @@ fn a_draft_of_decimals_largest_is_refused_where_summed() {
assert!(why.contains("too large to compute"), "{why}");
assert_eq!(l.post_entry(e).unwrap_err(), LedgerError::AmountOutOfRange);
}
// A member's capital moved past exact arithmetic (rules.md B-35, case
// 3, B-28): the target is refused, never a panic.
// A member's capital moved past exact arithmetic (BS-partner-3, case
// 3, BS-entry-4): the target is refused, never a panic.
let e = l.create_entry(d(2026, 3, 1), "huge capital");
for _ in 0..2 {
l.replay_add_line(e, cash, Side::Debit, usd(Decimal::MAX))
@@ -285,7 +285,7 @@ fn a_draft_of_decimals_largest_is_refused_where_summed() {
/// A document is restored as journaled: its total is exact, or refused
/// past exact arithmetic; what it owes is what the ledger lines tagged
/// with it carry (rules.md B-38), exact, whatever the journal held (paid
/// with it carry (BS-arap-2), exact, whatever the journal held (paid
/// above its total included); aging refuses a document whose total it
/// can't compute.
#[test]
@@ -363,7 +363,7 @@ fn documents_and_aging_are_exact_or_refused() {
(Decimal::from(11), -Decimal::ONE)
);
// A payment event naming an amount no line of its entry carries tags
// nothing, and is refused nothing (B-28).
// nothing, and is refused nothing (BS-entry-4).
l.replay_invoice_payment(1, -Decimal::ONE, p).unwrap();
assert_eq!(l.get_invoice(1).unwrap().balance(), Ok(-Decimal::ONE));
// A total of lines that overflow, and its balance; aging refuses it.
+8 -8
View File
@@ -42,7 +42,7 @@ fn usd(cents: i64) -> Money {
fn post(l: &mut Ledger, date: NaiveDate, desc: &str, lines: &[(AccountId, Side, i64)]) -> EntryId {
// As replay posts it: these books hold hand lines on receivables or
// payables (1200, 2000), which books an earlier version wrote still
// hold and every report must read; the control guard (rules.md B-38)
// hold and every report must read; the control guard (BS-arap-2)
// refuses them as new work.
ledger_core::parties::replaying(|| {
let e = l.create_entry(date, desc);
@@ -1115,7 +1115,7 @@ fn me_unexplained_equity_change_goes_in_other() {
/// 50.00).
///
/// ASSUMED: a closing entry's credit to a member's capital account is not
/// reported as a contribution (B-11: a close moves earnings), so January's
/// reported as a contribution (BS-period-1: a close moves earnings), so January's
/// statement shows contributions 1000 / 0, income 50.01 / 50.00.
#[test]
fn me_after_members_close_does_not_count_close_as_contribution() {
@@ -1473,7 +1473,7 @@ fn cf_undesignated_liability_is_operating() {
assert_eq!(cf.net_change_in_cash, c(58000));
}
/// Oracle: CF INVARIANT 5 / B-14 — closing entries never counted: after
/// Oracle: CF INVARIANT 5 / BS-statement-3 — closing entries never counted: after
/// closing February into retained earnings the February statement is
/// unchanged (NI still 400, 3999 not in financing).
#[test]
@@ -1792,7 +1792,7 @@ fn build_ordered(gens: &[Gen], scale: i64, order: &[usize], tag: bool) -> Books
let mut entries = Vec::new();
// As replay posts it: these books hold hand lines on receivables or
// payables (1200, 2000), which books an earlier version wrote still
// hold and every report must read; the control guard (rules.md B-38)
// hold and every report must read; the control guard (BS-arap-2)
// refuses them as new work.
ledger_core::parties::replaying(|| {
for g in gens {
@@ -1931,7 +1931,7 @@ fn opt_month() -> impl Strategy<Value = Option<u32>> {
proptest! {
#![proptest_config(ProptestConfig::with_cases(64))]
/// Oracle: TB INVARIANT 1 / B-6 — total debits equal total credits, and
/// Oracle: TB INVARIANT 1 / BS-statement-1 — total debits equal total credits, and
/// each total is its column's sum, for any as-of date, with or without a
/// close.
#[test]
@@ -2005,7 +2005,7 @@ proptest! {
prop_assert_eq!(many.total_debits, one.total_debits * kk);
}
/// Oracle: B-9 metamorphic — adding an entry and its reversal (same
/// Oracle: BS-ledger-5 metamorphic — adding an entry and its reversal (same
/// date) leaves TB and P&L unchanged at every date.
#[test]
fn prop_entry_plus_reversal_leaves_tb_and_pnl_unchanged(gens in arb_books(), extra in arb_gen(), as_of in 0u32..365) {
@@ -2222,7 +2222,7 @@ proptest! {
proptest! {
#![proptest_config(ProptestConfig::with_cases(64))]
/// Oracle: BS INVARIANT 1 / B-7 — assets = liabilities + equity (with
/// Oracle: BS INVARIANT 1 / BS-statement-2 — assets = liabilities + equity (with
/// current earnings), exactly; totals are line sums; never a revenue or
/// expense line; with or without a close (RE or members).
#[test]
@@ -2503,7 +2503,7 @@ proptest! {
/// Oracle: CF INVARIANT 2 against an independent model — financing is
/// the cash part of the equity and designated-debt movements: each
/// entry's cash applied to the sections moving against it, operating,
/// investing, financing, each up to its own movement (rules.md B-14
/// investing, financing, each up to its own movement (BS-statement-3
/// rule 3), then to the kinds within each section in their order;
/// plus what the loan or a member's capital paid or received for the
/// company (rule 11, D-42): the loan pays for operating lines (the
+12 -12
View File
@@ -2,7 +2,7 @@
//! (receivables, revenue, payables, general expense, retained earnings, the
//! seven payroll accounts) assigned to the chart's own accounts.
//!
//! Oracles are `docs/spec/rules.md` B-4 (the five elements) and B-23
//! Oracles are BS-ledger-2 (the five elements) and BS-ledger-8
//! (control roles), the spec block on `Ledger::assign_role`, the doc
//! comments of `Ledger::role_account`, `role_assignment`,
//! `check_assign_role`, `control_account`, `ControlAccount::key`, the spec
@@ -48,7 +48,7 @@ fn line(desc: &str, amount: &str) -> DocumentLine {
}
}
/// The thirteen role keys, as the spec lists them (B-23, B-41's
/// The thirteen role keys, as the spec lists them (BS-ledger-8, BS-arap-5's
/// bad_debts, and `UnknownRole`).
const KEYS: [&str; 13] = [
"receivables",
@@ -106,9 +106,9 @@ fn bal(l: &Ledger, id: AccountId) -> Decimal {
/// Draft, add lines, post. Panics on any refusal (setup only). Posted as
/// replay posts it: these books hold hand lines on receivables or payables
/// (moving a role's balance by hand, B-23's path before documents read
/// (moving a role's balance by hand, BS-ledger-8's path before documents read
/// their lines), which books an earlier version wrote still hold; the
/// control guard (rules.md B-38) refuses them as new work.
/// control guard (BS-arap-2) refuses them as new work.
fn post(l: &mut Ledger, date: NaiveDate, lines: &[(AccountId, Side, &str)]) -> EntryId {
ledger_core::parties::replaying(|| {
let id = l.try_create_entry(date, "test entry").unwrap();
@@ -250,7 +250,7 @@ fn alice() -> PayrollLine {
// ------------------------------------------------------------ the roles
/// Oracle: B-23 (and B-41 for bad_debts) names the roles and their default
/// Oracle: BS-ledger-8 (and BS-arap-5 for bad_debts) names the roles and their default
/// codes; `control_account` finds a role by its `key`; `UnknownRole` lists
/// the thirteen keys.
#[test]
@@ -601,7 +601,7 @@ fn an_unknown_account_is_refused() {
// ----------------------------------------- SCENARIO 2: type / placeholder
/// Oracle: SCENARIO 2 + INVARIANT 3 + B-4: every role refuses an account of
/// Oracle: SCENARIO 2 + INVARIANT 3 + BS-ledger-2: every role refuses an account of
/// each other type with ControlAccountMismatch naming the account, the
/// role, the type needed and the type found.
#[test]
@@ -688,7 +688,7 @@ fn none_is_refused_when_the_default_code_holds_a_wrong_typed_account() {
}
// The role assigned elsewhere, then 1200 taken by a wrong type (an
// assignment frees the code, B-23 / check_renumber_account): None is
// assignment frees the code, BS-ledger-8 / check_renumber_account): None is
// refused, and the assignment stays.
let (mut l, _) = books();
let ar = add(&mut l, "1100", "Trade Receivables", AccountType::Asset);
@@ -784,7 +784,7 @@ fn none_is_refused_when_its_codes_account_fills_another_role() {
// --------------------------------------------- SCENARIO 4: balances move
/// Oracle: SCENARIO 4 + B-23 ("moves only when its account holds no
/// Oracle: SCENARIO 4 + BS-ledger-8 ("moves only when its account holds no
/// balance, so the bookkeeper first moves the balance with an entry").
#[test]
fn receivables_cannot_move_while_holding_a_balance_but_can_once_moved_out() {
@@ -814,7 +814,7 @@ fn receivables_cannot_move_while_holding_a_balance_but_can_once_moved_out() {
other => panic!("expected DocumentRoleHoldsBalance, got {other:?}"),
}
// Moving the balance by hand is refused now (the control guard,
// rules.md B-38): until a role's balance moves with its documents
// BS-arap-2): until a role's balance moves with its documents
// (plan P4b S7), a receivables role holding a balance stays put.
let e = l.try_create_entry(d(2026, 3, 2), "move").unwrap();
assert!(matches!(
@@ -874,7 +874,7 @@ fn every_balance_sheet_role_holds_while_its_account_has_a_balance() {
);
if c.key == RECEIVABLES.key || c.key == PAYABLES.key {
// No document posted there: the balance is the chart's own,
// so the role moves (B-38); it can't come back to an account
// so the role moves (BS-arap-2); it can't come back to an account
// holding hand lines.
l.assign_role(c.key, Some(target)).unwrap();
assert!(
@@ -924,7 +924,7 @@ fn none_is_refused_while_the_assigned_balance_sheet_account_holds_a_balance() {
let _ = cash;
}
/// Oracle: SCENARIO 4 "Revenue and expense roles move freely"; B-23
/// Oracle: SCENARIO 4 "Revenue and expense roles move freely"; BS-ledger-8
/// "earlier postings stay where they are"; INVARIANT 4.
#[test]
fn revenue_and_expense_roles_move_even_with_a_balance() {
@@ -1048,7 +1048,7 @@ fn check_assign_role_agrees_and_does_not_mutate() {
// ------------------------------------------- renumbering and the codes
/// Oracle: B-23 + check_renumber_account ("an assigned role frees its
/// Oracle: BS-ledger-8 + check_renumber_account ("an assigned role frees its
/// code"); renumber_account SCENARIO 2 for an unassigned role's code.
#[test]
fn an_assigned_role_frees_its_code_for_renumbering() {
+9 -9
View File
@@ -547,11 +547,11 @@ fn statement_json(
/// The golden: every number in `golden/members_equity_two_member.json` was
/// computed by hand, from the entries, in
/// `plan/golden-worksheets/members_equity_two_member.md`, before the engine's
/// output was looked at. Rules: B-13 (capital account = contributions +
/// output was looked at. Rules: BS-partner-1 (capital account = contributions +
/// allocated income − distributions; cent rounding by largest remainder, the
/// odd cent to the member listed first; unclosed earnings split cumulatively)
/// and B-7 (the Total ties to balance-sheet equity). The same numbers hold
/// whether or not January is closed (B-13: a member's capital on a date never
/// and BS-statement-2 (the Total ties to balance-sheet equity). The same numbers hold
/// whether or not January is closed (BS-partner-1: a member's capital on a date never
/// moves when its period closes).
#[test]
fn golden_members_equity_two_member() {
@@ -1102,7 +1102,7 @@ fn cf_params(start: NaiveDate, end: NaiveDate, cash: AccountId) -> CashFlowParam
}
fn reconciles(cf: &ledger_core::CashFlowStatement) {
// B-14 / cash_flow INVARIANT 4: the three sections sum to the change in
// BS-statement-3 / cash_flow INVARIANT 4: the three sections sum to the change in
// cash, exactly, and net income and its reconciling items to operating.
assert_eq!(
cf.cash_from_operations + cf.cash_from_investing + cf.cash_from_financing,
@@ -1444,7 +1444,7 @@ fn lines(ls: &[ledger_core::reports::CashFlowLine]) -> Vec<(String, Decimal)> {
/// amounts borrowed"): borrowing and repayment are separate lines, one
/// per entry, borrowing first (each lender's, by code), then repayments.
/// The software the owner paid personally is borrowed from the owner and
/// spent on its date (rules.md B-14 rule 11, D-42: constructive receipt
/// spent on its date (BS-statement-3 rule 11, D-42: constructive receipt
/// and disbursement). Financing: +100 + 1,000 − 100 − 400 = 600; nothing
/// is disclosed.
#[test]
@@ -1487,7 +1487,7 @@ fn a_loan_the_entity_makes_is_investing_gross() {
assert_eq!(cf.cash_from_investing, dec(-300));
}
/// Oracle: D-42 (rules.md B-14 rule 11; ASC 230 is silent on a payment
/// Oracle: D-42 (BS-statement-3 rule 11; ASC 230 is silent on a payment
/// made on the entity's behalf, PwC FSP 6.9.3.1 and DART Roadmap 7.2
/// present it as constructive receipt and disbursement). The owner paying
/// software personally is cash the company borrowed (financing +100) and
@@ -1691,7 +1691,7 @@ mod cumulative_closes {
.collect()
}
/// Oracle: rules.md B-13 (cumulative closes; docs/testing.md #12),
/// Oracle: BS-partner-1 (cumulative closes; docs/testing.md #12),
/// hand-computed. Closing each cent on its own gives the earlier member
/// every tie: A 0.03, B 0.00 after three months. Cumulatively: after
/// month 1 the run's 0.01 splits A 0.01 / B 0; after month 2, 0.02
@@ -1723,7 +1723,7 @@ mod cumulative_closes {
}
proptest::proptest! {
/// Oracle: rules.md B-13, cumulative closes. For any run of monthly
/// Oracle: BS-partner-1, cumulative closes. For any run of monthly
/// profits and losses closed into three members at 33.33% /
/// 33.33% / 33.34%, each member's total from the run is within one
/// cent of their exact share of everything closed.
@@ -1782,7 +1782,7 @@ mod cumulative_closes {
assert_eq!((a, b), (cents("0.02"), cents("0")));
}
/// The rule since P3 (rules.md B-13, D-10): a close to retained
/// The rule since P3 (BS-partner-1, D-10): a close to retained
/// earnings allocates nothing to the members and is skipped, so March's
/// members close continues January's count: the running 0.02 splits
/// 0.01 / 0.01, and March gives B the cent.
+6 -6
View File
@@ -165,7 +165,7 @@ fn by_value(v: &mut serde_json::Value) {
/// The golden: every number in `golden/tax_summary_form_1065.json` was
/// computed by hand, from the fixture's entries, in
/// `plan/golden-worksheets/tax_summary_form_1065.md`, before the engine's
/// output was looked at. Rules: B-32 and `sources/irs-tax-lines.md` (the
/// output was looked at. Rules: BS-ledger-11 and `sources/irs-tax-lines.md` (the
/// category-to-line map; a contra-income expense account reduces receipts;
/// meals at 50% from the Schedule C line 24b instructions, so 333.33 is
/// 166.665, the cent half away from zero, 166.67; fines and penalties at 0%
@@ -228,7 +228,7 @@ fn category_books(category: &str, specs: &[(&str, &str, Option<&str>)]) -> Ledge
l
}
/// CHOICE (owner, 2026-11-07; rules.md B-32, B-21): a category rounds
/// CHOICE (owner, 2026-11-07; BS-ledger-11, BS-entry-3): a category rounds
/// once, on its total. Two Meals accounts of 1.01 at 50%: each share is
/// exactly 0.505, so rounding per account would give 0.51 + 0.51 = 1.02;
/// the exact sum 1.01 rounds once to 1.01. Book stays exact: 2.02.
@@ -441,8 +441,8 @@ fn a_sole_proprietor_cannot_deduct_a_gift_on_schedule_c() {
}
// ---------------------------------------------------------------------------
// Which accounts need a category, and the policy (P3, defect 8; rules.md
// B-32).
// Which accounts need a category, and the policy (P3, defect 8;
// BS-ledger-11).
// ---------------------------------------------------------------------------
fn set_policy(l: &mut Ledger, value: &str) {
@@ -634,11 +634,11 @@ fn under_refuse_a_needed_category_is_never_cleared() {
Err(LedgerError::UnknownAccount(999))
);
// The engine's own set_account_tax (which replay calls) never checks
// the policy (rules.md B-28): a journaled clear replays.
// the policy (BS-entry-4): a journaled clear replays.
l.set_account_tax(software, None, None).unwrap();
}
/// rules.md B-32 (review R3): every account a tool can require has a
/// BS-ledger-11 (review R3): every account a tool can require has a
/// category that fits it on every return: a disposal's gain or loss
/// account (revenue or expense: Form 4797), tax-exempt income on the
/// entity returns, and each control role's account.
+7 -7
View File
@@ -1,5 +1,5 @@
//! Spec tests for the K-1 worksheet's tax-basis capital
//! (`ledger_core::tax_capital`, rules.md B-36): Item L on the tax basis
//! (`ledger_core::tax_capital`, BS-partner-4): Item L on the tax basis
//! beside the book figures, every figure the books can't know left open
//! and named, and the reconciliation from book to tax capital.
//!
@@ -223,7 +223,7 @@ fn the_year() -> (Books, EntryId, AssetId, AssetId) {
(b, devices, laptop, camera)
}
/// Item L on the tax basis, per member, for the year (B-36): a cash
/// Item L on the tax basis, per member, for the year (BS-partner-4): a cash
/// contribution, a contribution of property, a distribution, a year of
/// depreciation.
#[test]
@@ -748,7 +748,7 @@ fn unequal_contributors_and_a_member_with_none() {
assert_eq!(none.reconciliation, Reconciliation::default());
}
/// The odd cent on the tax basis runs (B-36 with D-38; owner, 2026-10-22):
/// The odd cent on the tax basis runs (BS-partner-4 with D-38; owner, 2026-10-22):
/// three devices contributed 50/50, each worth less than its basis by an
/// odd number of cents, the built-in gain shared cumulatively, so the
/// members' tax property ends one cent apart, never three. By hand:
@@ -843,7 +843,7 @@ fn three_members(b: &mut Books) -> (AccountId, [MemberCapital; 3]) {
)
}
/// A member never takes a cent of an entry they had no part in (B-36,
/// A member never takes a cent of an entry they had no part in (BS-partner-4,
/// Form 1065 Item L: capital contributed is the basis of the property
/// that member contributed; P4 review, 2026-10-22). Three members; by
/// hand, each set of contributing members its own running split:
@@ -948,7 +948,7 @@ fn a_member_outside_an_entry_never_takes_its_cents() {
}
/// An entry's odd cent is the same whatever span the worksheet is asked
/// for (B-36; P4 review, 2026-10-22). Tobin and Morgan, 50/50: a monitor
/// for (BS-partner-4; P4 review, 2026-10-22). Tobin and Morgan, 50/50: a monitor
/// contributed 2026-01-01 (400.00, basis 412.37, gain −12.37), reversed
/// 2026-07-01; a desk contributed 2026-11-01 (600.00, basis 655.91, gain
/// −55.91). The reversal takes the monitor's split back out of the count,
@@ -999,7 +999,7 @@ fn an_entrys_odd_cent_is_the_same_in_every_span() {
/// The running split takes the entries in date order, whatever order
/// they were posted in, so next year's beginning is this year's ending
/// to the cent (B-36). Tobin and Morgan, 50/50: a chair dated 2027-03-01
/// to the cent (BS-partner-4). Tobin and Morgan, 50/50: a chair dated 2027-03-01
/// (250.00, basis 263.41) posted first, then a monitor dated 2026-01-01
/// (400.00, basis 412.37). The monitor comes first: −6.19 / −6.18, then
/// the chair −6.70 / −6.71. Taken in posting order the 2027 worksheet
@@ -1070,7 +1070,7 @@ fn largest_remainder(exact: &[i128], total: i128, negative: bool) -> Vec<i128> {
proptest! {
#![proptest_config(ProptestConfig::with_cases(5000))]
/// Law: RunningSplit INVARIANTS 1 and 2 (B-36 with D-38): for any run
/// Law: RunningSplit INVARIANTS 1 and 2 (BS-partner-4 with D-38): for any run
/// of splits, wholes of either sign to the cent (a third of them a few
/// cents, so the running whole often comes back to zero) and each its own
/// weights among up to four members (small ratios, scaled by a cent