Skip to content
Snippets Groups Projects
Commit dc650bc2 authored by Jeremy Reed's avatar Jeremy Reed
Browse files

Add decode() tests.

parent 78ecfe38
No related branches found
No related tags found
No related merge requests found
......@@ -149,6 +149,7 @@ mod tests {
return byte_arrays;
}
// encode() tests.
#[test]
fn should_encode_empty_vector_correctly() {
let actual = encode(&vec![]);
......@@ -169,14 +170,32 @@ mod tests {
}
}
// decode() tests.
#[test]
fn encode_empty_string_should_return_empty_string() {
let bytes: Vec<u8> = String::from("").into_bytes();
let actual: String = encode(&bytes);
assert!(actual.len() == 0);
assert!(actual == "");
fn decode_empty_string_should_return_empty_vector() {
let actual: Vec<u8> = decode(&String::from(""));
assert_eq!(actual, []);
}
#[test]
fn decode_should_decode_base64_strings_correctly() {
let base64_strings = get_base64_strings();
let plain_strings = get_plain_strings();
let mut i: usize = 0;
while i < base64_strings.len() {
let test_string = &base64_strings[i];
let actual: String = match String::from_utf8(decode(&test_string)) {
Ok(s) => s,
Err(e) => panic!("Invalid utf-8 sequence: {:?}", e),
};
assert_eq!(actual, plain_strings[i]);
i = i + 1;
}
}
// Helper function tests.
#[test]
fn get_number_of_pads_should_return_zero() {
let test_vec = String::from("Foo").into_bytes();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment