Extract Account into separate crate

korrat
Apr 1, 2023, 11:57 AM
NG5QXPZH5M5EMEQOUSI3VVFB4ORIARTE7WSVEHFG7NJ2S4MTAYFQC

Dependencies

  • [2] W3MWSSJ7 Add a templating engine for accounts
  • [3] R7S2CWF7 Add type for account segments
  • [4] YBARPI2B Make account templates owned
  • [5] R524JUUE Implement metadata & price directives
  • [6] SEEWF7KX Implement metadata on transactions
  • [7] 4UOASAH3 Make Acc and AccountTemplate zero-copy deserializable
  • [8] YDK6X6PP add a library of important types for beancount
  • [9] 2JBFREZG enable additional warnings
  • [10] SMBQYFPG Enable access to timestamps for directives
  • [*] 5PYSO4HI

Change contents

  • file addition: beancount (d--r------)
    [12.1]
  • file addition: account (d--r------)
    [0.1]
  • file addition: tests (d--r------)
    [0.24]
  • file addition: basic.rs (---r------)
    [0.45]
    use core::fmt::Debug;
    use core::hash::Hash;
    use core::str::FromStr;
    use beancount_account::Acc;
    use beancount_account::Account;
    use static_assertions::assert_impl_all;
    use test_case::test_case;
    assert_impl_all!(
    Account: Clone,
    Debug,
    FromStr,
    Hash,
    Ord,
    TryFrom<&'static str>
    );
    #[test_case("Assets"; "only top-level")]
    #[test_case("Cash"; "unknown top-level account")]
    #[test_case("Equity:OpeningBalances"; "subaccount")]
    #[test_case("Expenses:Banking-Fees"; "subaccount with dash")]
    #[test_case("Income:Sales:2022"; "subaccount starting with number")]
    #[test_case("Liabilities:Credit-Cards:VISA"; "multiple levels")]
    fn parse_when_valid(name: &str) {
    let acc = <&Acc>::try_from(name).unwrap();
    let account = Account::try_from(name).unwrap();
    assert_eq!(account, name);
    assert_eq!(acc, name);
    }
    #[test_case("Assets:Accounts_Receivable"; "invalid characters")]
    #[test_case("Assets:-Test"; "subaccount starting with dash")]
    #[test_case("Income::Sales"; "empty segment")]
    fn do_not_parse_when_invalid(name: &str) {
    <&Acc>::try_from(name).unwrap_err();
    }
  • file addition: src (d--r------)
    [0.24]
  • file move: account.rs (---r------)lib.rs (---r------)
    [0.1201]
    [3.11466]
  • edit in beancount/account/src/lib.rs at line 3
    [3.13676]
    [3.13676]
    use alloc::borrow::Cow;
  • edit in beancount/account/src/lib.rs at line 16
    [3.13938][3.13938:13962]()
    use alloc::borrow::Cow;
  • edit in beancount/account/src/lib.rs at line 24
    [3.11550][2.9697:9723]()
    pub(crate) mod template;
  • replacement in beancount/account/src/lib.rs at line 1219
    [3.25499][3.25499:25596]()
    r#"^(?:Assets|Equity|Expenses|Income|Liabilities)(?::[\p{Lu}\p{Nd}][-\p{L}\p{Nd}]*)*$"#,
    [3.25499]
    [3.25596]
    r#"^(?:[\p{Lu}\p{Nd}][-\p{L}\p{Nd}]*)(?::[\p{Lu}\p{Nd}][-\p{L}\p{Nd}]*)*$"#,
  • file addition: Cargo.toml (---r------)
    [0.24]
    [package]
    name = "beancount-account"
    version = "0.1.0"
    edition = "2021"
    # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    [dependencies]
    # Inherited dependencies
    delegate.workspace = true
    lazy-regex.workspace = true
    miette.workspace = true
    momo.workspace = true
    serde.workspace = true
    snafu.workspace = true
    [dev-dependencies]
    test-case.workspace = true
    static_assertions.workspace = true
  • edit in common/beancount-types/tests/snapshots/account_template__parsing_only_base_account_works.snap at line 3
    [2.183][2.183:202]()
    assertion_line: 30
  • replacement in common/beancount-types/tests/snapshots/account_template__parsing_only_base_account_works.snap at line 6
    [2.238][2.238:254]()
    base: Acc {
    [2.238]
    [2.254]
    base: Account {
  • replacement in common/beancount-types/tests/snapshots/account_template__parsing_base_account_and_trailing_selector_works.snap at line 6
    [2.3779][2.3779:3795]()
    base: Acc {
    [2.3779]
    [2.3795]
    base: Account {
  • replacement in common/beancount-types/tests/snapshots/account_template__parsing_base_account_and_multiple_trailing_selectors_works.snap at line 6
    [2.4164][2.4164:4180]()
    base: Acc {
    [2.4164]
    [2.4180]
    base: Account {
  • replacement in common/beancount-types/tests/snapshots/account_template__parsing_base_account_and_mixed_trailing_selectors_and_literals_works.snap at line 6
    [2.4752][2.4752:4768]()
    base: Acc {
    [2.4752]
    [2.4768]
    base: Account {
  • replacement in common/beancount-types/tests/snapshots/account_template__parsing_base_account_and_mixed_trailing_selectors_and_literals_works.snap at line 21
    [2.5036][2.5036:5054]()
    Seg {
    [2.5036]
    [2.5054]
    Segment {
  • edit in common/beancount-types/src/that.rs at line 1
    [3.2458][3.2459:2535](),[3.2535][3.3839:3919](),[3.3919][3.2535:2579](),[3.2535][3.2535:2579](),[3.2656][3.2656:3694]()
    mod account {
    use crate::account::Acc;
    use crate::account::Account;
    use core::fmt::Debug;
    use core::hash::Hash;
    use core::str::FromStr;
    use static_assertions::assert_impl_all;
    use test_case::test_case;
    assert_impl_all!(
    Account: Clone,
    Debug,
    FromStr,
    Hash,
    Ord,
    TryFrom<&'static str>
    );
    #[test_case("Assets"; "only top-level")]
    #[test_case("Equity:OpeningBalances"; "subaccount")]
    #[test_case("Expenses:Banking-Fees"; "subaccount with dash")]
    #[test_case("Income:Sales:2022"; "subaccount starting with number")]
    #[test_case("Liabilities:Credit-Cards:VISA"; "multiple levels")]
    fn parse_when_valid(name: &str) {
    let acc = <&Acc>::try_from(name).unwrap();
    let account = Account::try_from(name).unwrap();
    assert_eq!(account, name);
    assert_eq!(acc, name);
    }
    #[test_case("Cash"; "invalid account type")]
    #[test_case("Assets:Accounts_Receivable"; "invalid characters")]
    #[test_case("Assets:-Test"; "subaccount starting with dash")]
    #[test_case("Income::Sales"; "empty segment")]
    fn do_not_parse_when_invalid(name: &str) {
    <&Acc>::try_from(name).unwrap_err();
    }
    }
  • edit in common/beancount-types/src/lib.rs at line 5
    [2.9633]
    [2.9633]
    pub use beancount_account::Acc;
    pub use beancount_account::Account;
    pub use beancount_account::Seg;
    pub use beancount_account::Segment;
  • edit in common/beancount-types/src/lib.rs at line 11
    [3.20][3.4030:4092](),[2.9696][3.4030:4092](),[3.5874][3.4030:4092](),[3.4092][3.21:83]()
    pub use crate::account::Acc;
    pub use crate::account::Account;
    pub use crate::account::Seg;
    pub use crate::account::Segment;
  • file addition: account.rs (---r------)
    [3.44]
    pub(crate) mod template;
  • edit in common/beancount-types/src/account/template.rs at line 5
    [2.9827]
    [2.9827]
    use beancount_account::AccountError;
    use beancount_account::SegmentError;
  • edit in common/beancount-types/src/account/template.rs at line 13
    [2.9921][2.9921:9989]()
    use crate::account::AccountError;
    use crate::account::SegmentError;
  • edit in common/beancount-types/Cargo.toml at line 25
    [3.26128]
    [3.26128]
    # Workspace dependencies
    beancount-account.path = "../../beancount/account"