1
Fork 0
gravatar-rs/tests/lib.rs

59 lines
1.5 KiB
Rust
Raw Normal View History

2022-04-02 12:05:23 +00:00
use gravatar_rs::Generator;
const BAUKE_EMAIL: &str = "me@bauke.xyz";
2022-09-26 10:12:45 +00:00
const HOLLLO_EMAIL: &str = "helllo@holllo.org";
2022-04-02 12:05:23 +00:00
#[test]
fn test_hash_email() {
2022-04-02 13:19:19 +00:00
let samples = [("bauke", BAUKE_EMAIL), ("holllo", HOLLLO_EMAIL)];
let mut snapshot = vec![];
2022-04-02 13:19:19 +00:00
for (name, email) in samples {
snapshot.push((format!("hash-{name}"), Generator::hash_email(email)));
2022-04-02 13:19:19 +00:00
snapshot.push((
2022-04-02 13:19:19 +00:00
format!("hash-{name}-whitespace"),
Generator::hash_email(&format!(" {email} ")),
));
2022-04-02 13:19:19 +00:00
snapshot.push((
2022-04-02 13:19:19 +00:00
format!("hash-{name}-casing"),
Generator::hash_email(&email.to_uppercase()),
));
2022-04-02 13:19:19 +00:00
}
insta::assert_debug_snapshot!("hash-email", snapshot);
2022-04-02 12:05:23 +00:00
}
#[test]
fn test_generator() {
2022-04-02 13:19:19 +00:00
let emails = [BAUKE_EMAIL, HOLLLO_EMAIL];
let samples = [
("gravatar", Generator::default().base_url),
("libravatar", "cdn.libravatar.org".to_string()),
];
let mut snapshot = vec![];
2022-04-02 13:19:19 +00:00
for (name, base_url) in samples {
let generator = Generator::default().set_base_url(&base_url);
let urls = emails.map(|email| generator.generate(email));
snapshot.push((format!("generate-{name}"), urls));
2022-04-02 12:05:23 +00:00
}
insta::assert_debug_snapshot!("generator", snapshot);
2022-04-02 12:05:23 +00:00
}
2022-04-02 16:42:30 +00:00
#[test]
fn test_all_options() {
let generator = Generator::default()
.set_base_url("cdn.libravatar.org")
2022-04-02 19:58:41 +00:00
.set_default_image("identicon")
.set_force_default(true)
.set_image_size(128)
.set_include_file_extension(true)
.set_rating("pg");
2022-04-02 16:42:30 +00:00
let urls = [BAUKE_EMAIL, HOLLLO_EMAIL].map(|email| generator.generate(email));
insta::assert_debug_snapshot!("generate-options", urls);
}