basic.rs
// SPDX-FileCopyrightText: 2023 - 2024 Markus Haug (Korrat)
//
// SPDX-License-Identifier: EUPL-1.2
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?