XWHISGCP3WZJHEQXEFFGHR5JDVOD7NMRH5ZPWFVTWQPA5XJBZKNQC
TB2QGHXN2PTACZQG4M53QBG74IDGSDQPAFSTRZ7UNHHCAXRWQEZQC
WS3UUOV3DGSOZSN4V2O6YZDFO3M4NIC6BCYWGGEHFBCV4KZJPQHAC
YDK6X6PPD42DMLFGF6OO2O3G7GA4Z2PCIDJIREHX6XNX2NYEBJSQC
2JBFREZGJ2PST2DE3ZVDQADXAOFXBYPMSFTG7C65GDKLOZGETTGAC
NG5QXPZH5M5EMEQOUSI3VVFB4ORIARTE7WSVEHFG7NJ2S4MTAYFQC
R7S2CWF72WQTE447Q62PKCVJSSCEXHMVUJ33Z6IN6NREOUSD4WNQC
R524JUUE57KNHXLPN52X6DWK6PPQPBG5DXYNSVLGSEI5UMYXWDMQC
SEEWF7KXEUNPVQBZUZ3ZXU4BIADFUEULIKAD3OMKSNRBDNJXRPLQC
RI7HQBYA7OZBTINMECRKAM5JCCMI3HDLD2CBNYT2OVIHKZPZIWDAC
6MR76MLLBLJUVM4K4VI3SVDYLN67FDG3VTLP4S2QD4Q2QO5UKPKAC
I2P2FTLEKLICJKHQ3FHOLRQRQYGZCJTCTU2MWXU2TMIRIKG6YFCQC
UESS5YZE6ZHPMVUL2P2OACW2Y2QLFLLLLC3F3JAENVH6A7REKLBAC
ZVTVMOZQCMKERJXJOVZWYYIHY7GCHAA4RTVCUZBIHXWDQJIACPMAC
4W4CDACXFPTAKZP52OLER7S5GLCRADMCTPHJL27BNNJLT4BVF5TQC
mod amount {
use {
crate::Amount,
core::{fmt::Debug, hash::Hash, str::FromStr},
static_assertions::assert_impl_all,
test_case::test_case,
};
assert_impl_all!(
Amount: Copy,
Debug,
FromStr,
Hash,
PartialOrd,
TryFrom<&'static str>
);
#[test_case("0 EUR"; "zero")]
#[test_case("15 USD"; "integer amount")]
#[test_case("0.30 CAD"; "fractional amount")]
#[test_case("0.0000067 ETH"; "arbitrary precision")]
#[test_case("-16.93 USD"; "negative amount")]
fn parse_when_valid(amount: &str) {
let account = Amount::try_from(amount).unwrap();
assert_eq!(account.to_string(), amount);
}
#[test_case(" EUR"; "missing units")]
#[test_case("15 "; "missing commodity")]
#[test_case("15,000.00 USD"; "thousands separator")]
#[test_case("15000,00 USD"; "invalid decimal separator")]
fn do_not_parse_when_invalid(amount: &str) {
Amount::try_from(amount).unwrap_err();
}
}
use core::fmt::Debug;
use core::hash::Hash;
use core::str::FromStr;
use beancount_amount::Amount;
use static_assertions::assert_impl_all;
use test_case::test_case;
assert_impl_all!(
Amount: Copy,
Debug,
FromStr,
Hash,
PartialOrd,
TryFrom<&'static str>
);
#[test_case("0 EUR"; "zero")]
#[test_case("15 USD"; "integer amount")]
#[test_case("0.30 CAD"; "fractional amount")]
#[test_case("0.0000067 ETH"; "arbitrary precision")]
#[test_case("-16.93 USD"; "negative amount")]
fn parse_when_valid(amount: &str) {
let account = Amount::try_from(amount).unwrap();
assert_eq!(account.to_string(), amount);
}
#[test_case(" EUR"; "missing units")]
#[test_case("15 "; "missing commodity")]
#[test_case("15,000.00 USD"; "thousands separator")]
#[test_case("15000,00 USD"; "invalid decimal separator")]
fn do_not_parse_when_invalid(amount: &str) {
Amount::try_from(amount).unwrap_err();
}
[package]
name = "beancount-amount"
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
version.workspace = true
[dependencies]
# Inherited dependencies
delegate.workspace = true
lazy-regex.workspace = true
miette.workspace = true
momo.workspace = true
rust_decimal.workspace = true
serde.workspace = true
snafu.workspace = true
# Workspace dependencies
beancount-commodity.workspace = true
[dev-dependencies]
static_assertions.workspace = true
test-case.workspace = true