#[cfg(test)]
mod currency_code__enum {
use super::super::*;
#[test]
fn all() {
let codes = CurrencyCode::all();
assert_eq!(codes.len(), 179);
assert!(codes.contains(&CurrencyCode::USD));
assert!(codes.contains(&CurrencyCode::EUR));
assert!(codes.contains(&CurrencyCode::GBP));
}
#[test]
fn currency() {
let currency = CurrencyCode::USD.currency();
assert_eq!(currency.name(), "United States dollar");
assert_eq!(currency.code(), CurrencyCode::USD);
}
#[test]
fn currency__all() {
#[expect(clippy::iter_over_hash_type, reason = "Order is not important here")]
for currency in CURRENCIES.keys() {
assert_eq!(currency.code().currency(), *currency);
}
}
}
#[cfg(test)]
mod currency_code__traits {
use super::super::*;
use claims::assert_err;
use serde_json;
#[test]
fn as_str() {
assert_eq!(CurrencyCode::USD.as_str(), "USD");
}
#[test]
fn debug() {
assert_eq!(format!("{:?}", CurrencyCode::USD), "USD");
}
#[test]
fn deserialize() {
let code1: CurrencyCode = serde_json::from_str(r#""USD""#).unwrap();
assert_eq!(code1, CurrencyCode::USD);
let code2: CurrencyCode = serde_json::from_str(r#""usd""#).unwrap();
assert_eq!(code2, CurrencyCode::USD);
}
#[test]
fn display() {
let code = CurrencyCode::USD;
assert_eq!(format!("{code}"), "USD");
assert_eq!(code.to_string(), "USD");
}
#[test]
fn eq() {
assert_eq!(CurrencyCode::USD, CurrencyCode::USD);
}
#[test]
fn ne() {
assert_ne!(CurrencyCode::USD, CurrencyCode::EUR);
}
#[test]
fn from__currency_code_for_u16() {
let code = CurrencyCode::USD;
assert_eq!(u16::from(code), 840);
assert_eq!(code as u16, 840);
let int: u16 = code.into();
assert_eq!(int, 840);
}
#[test]
fn from__currency_code_for_string() {
let code = CurrencyCode::USD;
assert_eq!(String::from(code), "USD");
let str: String = code.into();
assert_eq!(str, "USD");
}
#[test]
fn from_str() {
assert_eq!(CurrencyCode::from_str("USD").unwrap(), CurrencyCode::USD);
assert_eq!(CurrencyCode::from_str("usd").unwrap(), CurrencyCode::USD);
let err = CurrencyCode::from_str("FOO");
assert_err!(&err);
assert_eq!(err.unwrap_err(), "Invalid CurrencyCode: FOO");
}
#[test]
fn serialize() {
assert_eq!(serde_json::to_string(&CurrencyCode::USD).unwrap(), r#""USD""#);
}
#[test]
fn try_from__u16() {
assert_eq!(CurrencyCode::try_from(840).unwrap(), CurrencyCode::USD);
let err = CurrencyCode::try_from(000);
assert_err!(&err);
assert_eq!(err.unwrap_err(), "Invalid CurrencyCode: 0");
}
#[test]
fn try_from__string() {
assert_eq!(CurrencyCode::try_from(s!("USD")).unwrap(), CurrencyCode::USD);
assert_eq!(CurrencyCode::try_from(s!("usd")).unwrap(), CurrencyCode::USD);
let err = CurrencyCode::try_from(s!("FOO"));
assert_err!(&err);
assert_eq!(err.unwrap_err(), "Invalid CurrencyCode: FOO");
}
}
#[cfg(test)]
mod currency__enum {
use super::super::*;
#[test]
fn all() {
let currencies = Currency::all();
assert_eq!(currencies.len(), 179);
assert!(currencies.contains(&Currency::USD));
assert!(currencies.contains(&Currency::EUR));
assert!(currencies.contains(&Currency::GBP));
}
#[test]
fn info() {
let info = Currency::USD.info();
assert_eq!(info.name, "United States dollar");
assert_eq!(info.code, CurrencyCode::USD);
}
#[test]
fn name() {
assert_eq!(Currency::GBP.name(), "Pound sterling");
}
#[test]
fn code() {
assert_eq!(Currency::GBP.code(), CurrencyCode::GBP);
}
#[test]
fn digits() {
assert_eq!(Currency::GBP.digits(), 2);
}
#[test]
fn countries() {
assert_eq!(Currency::GBP.countries(), &vh![ CountryCode: GB, GG, IM, JE, SH ]);
}
#[test]
fn countries__relationships() {
#[expect(clippy::iter_over_hash_type, reason = "Order is not important here")]
for currency in CURRENCIES.keys() {
for country_code in currency.countries() {
assert!(country_code.country().currencies().contains(¤cy.code()));
}
}
}
}
#[cfg(test)]
mod currency__traits {
use super::super::*;
use claims::assert_err;
use serde_json;
#[test]
fn as_str() {
assert_eq!(Currency::USD.as_str(), "United States dollar");
}
#[test]
fn debug() {
assert_eq!(format!("{:?}", Currency::USD), "USD: United States dollar");
}
#[test]
fn deserialize() {
let currency: Currency = serde_json::from_str(r#""United States dollar""#).unwrap();
assert_eq!(currency, Currency::USD);
}
#[test]
fn display() {
let currency = Currency::USD;
assert_eq!(format!("{currency}"), "United States dollar");
assert_eq!(currency.to_string(), "United States dollar");
}
#[test]
fn eq() {
assert_eq!(Currency::USD, Currency::USD);
}
#[test]
fn ne() {
assert_ne!(Currency::USD, Currency::EUR);
}
#[test]
fn from__currency_for_string() {
let currency = Currency::USD;
assert_eq!(String::from(currency), "United States dollar");
let str: String = currency.into();
assert_eq!(str, "United States dollar");
}
#[test]
fn from_str() {
assert_eq!(Currency::from_str("United States dollar").unwrap(), Currency::USD);
let err = Currency::from_str("Foo dollar");
assert_err!(&err);
assert_eq!(err.unwrap_err(), "Invalid Currency: Foo dollar");
}
#[test]
fn serialize() {
assert_eq!(serde_json::to_string(&Currency::USD).unwrap(), r#""United States dollar""#);
}
#[test]
fn try_from__string() {
assert_eq!(Currency::from_str("United States dollar").unwrap(), Currency::USD);
let err = Currency::from_str("Foo dollar");
assert_err!(&err);
assert_eq!(err.unwrap_err(), "Invalid Currency: Foo dollar");
}
}