2 settings::structs::Settings,
9 scrape_text_for_mentions,
16 fn test_mentions_regex() {
17 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)";
18 let mentions = scrape_text_for_mentions(text);
20 assert_eq!(mentions[0].name, "tedu".to_string());
21 assert_eq!(mentions[0].domain, "honk.teduangst.com".to_string());
22 assert_eq!(mentions[1].domain, "lemmy-alpha:8540".to_string());
26 fn test_valid_actor_name() {
27 let actor_name_max_length = Settings::init().unwrap().actor_name_max_length;
28 assert!(is_valid_actor_name("Hello_98", actor_name_max_length));
29 assert!(is_valid_actor_name("ten", actor_name_max_length));
30 assert!(!is_valid_actor_name("Hello-98", actor_name_max_length));
31 assert!(!is_valid_actor_name("a", actor_name_max_length));
32 assert!(!is_valid_actor_name("", actor_name_max_length));
36 fn test_valid_display_name() {
37 let actor_name_max_length = Settings::init().unwrap().actor_name_max_length;
38 assert!(is_valid_display_name("hello @there", actor_name_max_length));
39 assert!(!is_valid_display_name(
44 // Make sure zero-space with an @ doesn't work
45 assert!(!is_valid_display_name(
46 &format!("{}@my name is", '\u{200b}'),
52 fn test_valid_post_title() {
53 assert!(is_valid_post_title("Post Title"));
54 assert!(is_valid_post_title(" POST TITLE 😃😃😃😃😃"));
55 assert!(!is_valid_post_title("\n \n \n \n ")); // tabs/spaces/newlines
59 fn test_valid_matrix_id() {
60 assert!(is_valid_matrix_id("@dess:matrix.org"));
61 assert!(!is_valid_matrix_id("dess:matrix.org"));
62 assert!(!is_valid_matrix_id(" @dess:matrix.org"));
63 assert!(!is_valid_matrix_id("@dess:matrix.org t"));
67 fn test_slur_filter() {
68 let slur_regex = Settings::init().unwrap().slur_regex();
70 "faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
71 let slur_free = "No slurs here";
73 remove_slurs(test, &slur_regex),
74 "*removed* test *removed* *removed* *removed* *removed*. Capitalized *removed*. This is a bunch of other safe text."
78 let has_slurs_vec = vec![
86 let has_slurs_err_str = "No slurs - Niggerz, cocksucker, faggot, kike, retardeds, tranny";
88 assert_eq!(slur_check(test, &slur_regex), Err(has_slurs_vec));
89 assert_eq!(slur_check(slur_free, &slur_regex), Ok(()));
90 if let Err(slur_vec) = slur_check(test, &slur_regex) {
91 assert_eq!(&slurs_vec_to_str(slur_vec), has_slurs_err_str);
95 // These helped with testing
97 // fn test_send_email() {
98 // let result = send_email("not a subject", "test_email@gmail.com", "ur user", "<h1>HI there</h1>");
99 // assert!(result.is_ok());