mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Add LemmyResult to slurs tests
This commit is contained in:
parent
664c51da8e
commit
d4a09cfc6a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user