2 is_valid_community_name,
8 scrape_text_for_mentions,
14 fn test_mentions_regex() {
15 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)";
16 let mentions = scrape_text_for_mentions(text);
18 assert_eq!(mentions[0].name, "tedu".to_string());
19 assert_eq!(mentions[0].domain, "honk.teduangst.com".to_string());
20 assert_eq!(mentions[1].domain, "lemmy-alpha:8540".to_string());
24 fn test_valid_register_username() {
25 assert!(is_valid_username("Hello_98"));
26 assert!(is_valid_username("ten"));
27 assert!(!is_valid_username("Hello-98"));
28 assert!(!is_valid_username("a"));
29 assert!(!is_valid_username(""));
33 fn test_valid_display_name() {
34 assert!(is_valid_display_name("hello @there"));
35 assert!(!is_valid_display_name("@hello there"));
37 // Make sure zero-space with an @ doesn't work
38 assert!(!is_valid_display_name(&format!(
45 fn test_valid_community_name() {
46 assert!(is_valid_community_name("example"));
47 assert!(is_valid_community_name("example_community"));
48 assert!(!is_valid_community_name("Example"));
49 assert!(!is_valid_community_name("Ex"));
50 assert!(!is_valid_community_name(""));
54 fn test_valid_post_title() {
55 assert!(is_valid_post_title("Post Title"));
56 assert!(is_valid_post_title(" POST TITLE 😃😃😃😃😃"));
57 assert!(!is_valid_post_title("\n \n \n \n ")); // tabs/spaces/newlines
61 fn test_valid_matrix_id() {
62 assert!(is_valid_matrix_id("@dess:matrix.org"));
63 assert!(!is_valid_matrix_id("dess:matrix.org"));
64 assert!(!is_valid_matrix_id(" @dess:matrix.org"));
65 assert!(!is_valid_matrix_id("@dess:matrix.org t"));
69 fn test_slur_filter() {
71 "faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
72 let slur_free = "No slurs here";
75 "*removed* test *removed* *removed* *removed* *removed*. Capitalized *removed*. This is a bunch of other safe text."
79 let has_slurs_vec = vec![
87 let has_slurs_err_str = "No slurs - Niggerz, cocksucker, faggot, kike, retardeds, tranny";
89 assert_eq!(slur_check(test), Err(has_slurs_vec));
90 assert_eq!(slur_check(slur_free), Ok(()));
91 if let Err(slur_vec) = slur_check(test) {
92 assert_eq!(&slurs_vec_to_str(slur_vec), has_slurs_err_str);
96 // These helped with testing
98 // fn test_send_email() {
99 // let result = send_email("not a subject", "test_email@gmail.com", "ur user", "<h1>HI there</h1>");
100 // assert!(result.is_ok());