2 is_valid_community_name,
4 is_valid_preferred_username,
7 scrape_text_for_mentions,
13 fn test_mentions_regex() {
14 let text = "Just read a great blog post by [@tedu@honk.teduangst.com](/u/test). And another by !test_community@fish.teduangst.com . Another [@lemmy@lemmy-alpha:8540](/u/fish)";
15 let mentions = scrape_text_for_mentions(text);
17 assert_eq!(mentions[0].name, "tedu".to_string());
18 assert_eq!(mentions[0].domain, "honk.teduangst.com".to_string());
19 assert_eq!(mentions[1].domain, "lemmy-alpha:8540".to_string());
23 fn test_valid_register_username() {
24 assert!(is_valid_username("Hello_98"));
25 assert!(is_valid_username("ten"));
26 assert!(!is_valid_username("Hello-98"));
27 assert!(!is_valid_username("a"));
28 assert!(!is_valid_username(""));
32 fn test_valid_preferred_username() {
33 assert!(is_valid_preferred_username("hello @there"));
34 assert!(!is_valid_preferred_username("@hello there"));
38 fn test_valid_community_name() {
39 assert!(is_valid_community_name("example"));
40 assert!(is_valid_community_name("example_community"));
41 assert!(!is_valid_community_name("Example"));
42 assert!(!is_valid_community_name("Ex"));
43 assert!(!is_valid_community_name(""));
47 fn test_valid_post_title() {
48 assert!(is_valid_post_title("Post Title"));
49 assert!(is_valid_post_title(" POST TITLE 😃😃😃😃😃"));
50 assert!(!is_valid_post_title("\n \n \n \n ")); // tabs/spaces/newlines
54 fn test_slur_filter() {
56 "faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
57 let slur_free = "No slurs here";
60 "*removed* test *removed* *removed* *removed* *removed*. Capitalized *removed*. This is a bunch of other safe text."
64 let has_slurs_vec = vec![
72 let has_slurs_err_str = "No slurs - Niggerz, cocksucker, faggot, kike, retardeds, tranny";
74 assert_eq!(slur_check(test), Err(has_slurs_vec));
75 assert_eq!(slur_check(slur_free), Ok(()));
76 if let Err(slur_vec) = slur_check(test) {
77 assert_eq!(&slurs_vec_to_str(slur_vec), has_slurs_err_str);
81 // These helped with testing
83 // fn test_send_email() {
84 // let result = send_email("not a subject", "test_email@gmail.com", "ur user", "<h1>HI there</h1>");
85 // assert!(result.is_ok());