conversions5

This commit is contained in:
Filipriec
2026-08-23 15:50:03 +02:00
parent af7016e4c7
commit 0c33d1fa5c
20 changed files with 1197 additions and 845 deletions

View File

@@ -15,14 +15,6 @@ pub use rusty_money::iso;
/// whitespace, and any length but three. Normalising here instead would let a
/// value be written in one spelling and compared in another.
pub fn require_iso_currency_code(currency_code: &str) -> Result<&'static iso::Currency, String> {
if currency_code.len() != 3
|| !currency_code
.chars()
.all(|character| character.is_ascii_uppercase())
{
return Err("Currency must be a canonical uppercase ISO-4217 code".to_string());
}
iso::find(currency_code).ok_or_else(|| format!("Unknown ISO-4217 currency: {currency_code}"))
}
@@ -42,7 +34,18 @@ mod tests {
#[test]
fn non_canonical_or_unknown_codes_are_rejected() {
for currency_code in [
"", "E", "EU", "EURO", "eur", "Eur", " EUR", "EUR ", "E R", "E\u{20AC}R", "AAA", "123",
"",
"E",
"EU",
"EURO",
"eur",
"Eur",
" EUR",
"EUR ",
"E R",
"E\u{20AC}R",
"AAA",
"123",
] {
assert!(
require_iso_currency_code(currency_code).is_err(),