NG5QXPZH5M5EMEQOUSI3VVFB4ORIARTE7WSVEHFG7NJ2S4MTAYFQC
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();
}
[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
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();
}
}
pub(crate) mod template;