From ade3e8a4369b8caf7ddfb01b46c96e5df31a4504 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Sun, 24 Sep 2023 18:51:15 +0300 Subject: [PATCH] Test alphabet-related panics --- src/decoder.rs | 2 +- src/tests.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/decoder.rs b/src/decoder.rs index 21a3cf2..36242cb 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -63,7 +63,7 @@ impl Encoding { let byte = alphabet_bytes[index]; compile_assert!( byte < 0x80, - "Alphabet '", alphabet => clip(64, ""), "' contains non-ASCII character at ", + "Alphabet '", alphabet => clip(64, ""), "' contains non-ASCII character at position ", index => fmt::() ); let byte_idx = byte as usize; diff --git a/src/tests.rs b/src/tests.rs index e0f075e..9be2205 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -102,6 +102,24 @@ fn mixed_base64_alphabet_leads_to_panic() { Decoder::Base64.decode::<6>(b"Pj4-Pz8/"); } +#[test] +#[should_panic(expected = "Invalid alphabet length 5; must be one of 2, 4, 8, 16, 32, or 64")] +fn invalid_alphabet_length() { + Decoder::custom("what?"); +} + +#[test] +#[should_panic(expected = "Alphabet 'teß' contains non-ASCII character at position 2")] +fn non_ascii_char_in_alphabet() { + Decoder::custom("teß"); +} + +#[test] +#[should_panic(expected = "Alphabet character 'a' is mentioned several times")] +fn duplicate_char_in_alphabet() { + Decoder::custom("alphabet"); +} + #[test] #[should_panic(expected = "input decodes to 6 bytes, while type inference implies 3.")] fn input_length_overflow() {