use core::str;
use rb64::decode;
#[test]
fn hello_world() {
let decoded = decode("SGVsbG8gd29ybGQh").expect("Expected correct decoding");
let decoded = str::from_utf8(&decoded).expect("Expected valid UTF-8");
assert_eq!(decoded, "Hello world!");
}
#[test]
fn padding() {
let decoded =
decode("VGhpcyBmcmFnbWVudCBoYXMgcGFkZGluZw==").expect("Expected correct decoding");
let decoded = str::from_utf8(&decoded).expect("Expected valid UTF-8");
assert_eq!(decoded, "This fragment has padding");
let decoded = decode("aGk=").expect("Expected correct decoding");
let decoded = str::from_utf8(&decoded).expect("Expected valid UTF-8");
assert_eq!(decoded, "hi");
}
#[test]
fn invalid() {
match decode("abc&") {
Err(err) => assert_eq!(err, "Unknown character to decode: '&'"),
Ok(_) => panic!("Expected Err"),
}
}
#[test]
fn short() {
match decode("aa") {
Err(err) => assert_eq!(err, "Base64 string length must be multiple of 4"),
Ok(_) => panic!("Expected Err"),
}
}