Skip to content

Commit

Permalink
Test alphabet-related panics
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Sep 24, 2023
1 parent 65445a5 commit ade3e8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>()
);
let byte_idx = byte as usize;
Expand Down
18 changes: 18 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ade3e8a

Please sign in to comment.