Skip to content

Commit

Permalink
Add unit tests for escape_email_with_display_name
Browse files Browse the repository at this point in the history
  • Loading branch information
robsdedude committed Nov 2, 2023
1 parent 2e09bc1 commit 693f81f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,4 +828,43 @@ mod test {
assert_eq!(metadata.license_files[2], manifest_dir.join("NOTICE.md"));
assert_eq!(metadata.license_files[3], manifest_dir.join("AUTHORS.txt"));
}

#[test]
fn test_escape_email_with_display_name_without_special_characters() {
let display_name = "Foo Bar !#$%&'*+-/=?^_`{|}~ 123";
let email = "[email protected]";
let result = escape_email_with_display_name(display_name, email);
assert_eq!(
result,
"Foo Bar !#$%&'*+-/=?^_`{|}~ 123 <[email protected]>"
);
}

#[test]
fn test_escape_email_with_display_name_with_special_characters() {
let tests = [
("Foo ( Bar", "\"Foo ( Bar\""),
("Foo ) Bar", "\"Foo ) Bar\""),
("Foo < Bar", "\"Foo < Bar\""),
("Foo > Bar", "\"Foo > Bar\""),
("Foo @ Bar", "\"Foo @ Bar\""),
("Foo , Bar", "\"Foo , Bar\""),
("Foo ; Bar", "\"Foo ; Bar\""),
("Foo : Bar", "\"Foo : Bar\""),
("Foo \\ Bar", "\"Foo \\\\ Bar\""),
("Foo \" Bar", "\"Foo \\\" Bar\""),
("Foo . Bar", "\"Foo . Bar\""),
("Foo [ Bar", "\"Foo [ Bar\""),
("Foo ] Bar", "\"Foo ] Bar\""),
("Foo ) Bar", "\"Foo ) Bar\""),
("Foo ) Bar", "\"Foo ) Bar\""),
("Foo, Bar", "\"Foo, Bar\""),
];
for (display_name, expected_name) in tests {
let email = "[email protected]";
let result = escape_email_with_display_name(display_name, email);
let expected = format!("{expected_name} <{email}>");
assert_eq!(result, expected);
}
}
}

0 comments on commit 693f81f

Please sign in to comment.