Add LemmyResult to slurs tests

This commit is contained in:
netbrum 2024-09-25 20:36:44 +02:00
parent 664c51da8e
commit d4a09cfc6a

View File

@ -61,16 +61,18 @@ pub(crate) fn slurs_vec_to_str(slurs: &[&str]) -> String {
}
#[cfg(test)]
#[expect(clippy::unwrap_used)]
mod test {
use crate::utils::slurs::{remove_slurs, slur_check, slurs_vec_to_str};
use crate::{
error::LemmyResult,
utils::slurs::{remove_slurs, slur_check, slurs_vec_to_str},
};
use pretty_assertions::assert_eq;
use regex::RegexBuilder;
#[test]
fn test_slur_filter() {
let slur_regex = Some(RegexBuilder::new(r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|ni((g{2,}|q)+|[gq]{2,})[e3r]+(s|z)?|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().unwrap());
fn test_slur_filter() -> LemmyResult<()> {
let slur_regex = Some(RegexBuilder::new(r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|ni((g{2,}|q)+|[gq]{2,})[e3r]+(s|z)?|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build()?);
let test =
"faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
let slur_free = "No slurs here";
@ -95,6 +97,8 @@ mod test {
if let Err(slur_vec) = slur_check(test, &slur_regex) {
assert_eq!(&slurs_vec_to_str(&slur_vec), has_slurs_err_str);
}
Ok(())
}
// These helped with testing