WS3UUOV3DGSOZSN4V2O6YZDFO3M4NIC6BCYWGGEHFBCV4KZJPQHAC
SMBQYFPGAKUWTAAJDS4VW3YI4OC3XPXIXJYJ5MBEGNH7FKGIVYJAC
NG5QXPZH5M5EMEQOUSI3VVFB4ORIARTE7WSVEHFG7NJ2S4MTAYFQC
QNGOXZL4NWSLMBCXA4GL46V5W3I6MXZZARCYKOPJHABBK46C7JJAC
YDK6X6PPD42DMLFGF6OO2O3G7GA4Z2PCIDJIREHX6XNX2NYEBJSQC
2JBFREZGJ2PST2DE3ZVDQADXAOFXBYPMSFTG7C65GDKLOZGETTGAC
4W4CDACXFPTAKZP52OLER7S5GLCRADMCTPHJL27BNNJLT4BVF5TQC
I2P2FTLEKLICJKHQ3FHOLRQRQYGZCJTCTU2MWXU2TMIRIKG6YFCQC
ZVTVMOZQCMKERJXJOVZWYYIHY7GCHAA4RTVCUZBIHXWDQJIACPMAC
mod commodities {
use {
crate::Commodity,
core::{fmt::Debug, hash::Hash, str::FromStr},
static_assertions::assert_impl_all,
test_case::test_case,
};
assert_impl_all!(
Commodity: Copy,
Debug,
FromStr,
Hash,
Ord,
TryFrom<&'static str>
);
#[test_case("A"; "single letter")]
#[test_case("USD"; "dollar")]
#[test_case("EUR"; "euro")]
#[test_case("MSFT"; "stock")]
#[test_case("AIRMILE"; "creative")]
#[test_case("DE.-_3"; "with special characters")]
fn parse_when_valid(name: &str) {
let commodity = Commodity::try_from(name).unwrap();
assert_eq!(commodity.to_string(), name);
}
#[test_case("0"; "starting with number")]
#[test_case("D-"; "ending with dash")]
#[test_case("E_"; "ending with underscore")]
#[test_case("X."; "ending with dot")]
#[test_case("X 3"; "containing space")]
#[test_case("X\\0"; "containing backslash")]
fn do_not_parse_when_invalid(name: &str) {
Commodity::try_from(name).unwrap_err();
}
// TODO proptest?
}
use core::fmt::Debug;
use core::hash::Hash;
use core::str::FromStr;
use beancount_commodity::Commodity;
use static_assertions::assert_impl_all;
use test_case::test_case;
assert_impl_all!(
Commodity: Copy,
Debug,
FromStr,
Hash,
Ord,
TryFrom<&'static str>
);
#[test_case("A"; "single letter")]
#[test_case("USD"; "dollar")]
#[test_case("EUR"; "euro")]
#[test_case("MSFT"; "stock")]
#[test_case("AIRMILE"; "creative")]
#[test_case("DE.-_3"; "with special characters")]
fn parse_when_valid(name: &str) {
let commodity = Commodity::try_from(name).unwrap();
assert_eq!(commodity.to_string(), name);
}
#[test_case("0"; "starting with number")]
#[test_case("D-"; "ending with dash")]
#[test_case("E_"; "ending with underscore")]
#[test_case("X."; "ending with dot")]
#[test_case("X 3"; "containing space")]
#[test_case("X\\0"; "containing backslash")]
fn do_not_parse_when_invalid(name: &str) {
Commodity::try_from(name).unwrap_err();
}
// TODO proptest?
[package]
name = "beancount-commodity"
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
version.workspace = true
[dependencies]
# Inherited dependencies
arrayvec.workspace = true
delegate.workspace = true
lazy-regex.workspace = true
miette.workspace = true
serde.workspace = true
snafu.workspace = true
[dev-dependencies]
static_assertions.workspace = true
test-case.workspace = true
test-case.workspace = true