-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement WithExactWord to allow stricter matches #107
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -548,6 +548,36 @@ func TestFalsePositives(t *testing.T) { | |||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func TestExactWord(t *testing.T) { | ||||||||||||||||||
accept_sentences := []string{ | ||||||||||||||||||
"I'm an analyst", | ||||||||||||||||||
} | ||||||||||||||||||
reject_sentences := []string{"Go away, ass."} | ||||||||||||||||||
tests := []struct { | ||||||||||||||||||
name string | ||||||||||||||||||
profanityDetector *ProfanityDetector | ||||||||||||||||||
}{ | ||||||||||||||||||
{ | ||||||||||||||||||
name: "With Empty FalsePositives", | ||||||||||||||||||
profanityDetector: NewProfanityDetector().WithExactWord(true).WithSanitizeSpecialCharacters(true).WithCustomDictionary(DefaultProfanities, nil, nil), | ||||||||||||||||||
}, | ||||||||||||||||||
} | ||||||||||||||||||
for _, tt := range tests { | ||||||||||||||||||
t.Run(tt.name, func(t *testing.T) { | ||||||||||||||||||
for _, s := range accept_sentences { | ||||||||||||||||||
if tt.profanityDetector.IsProfane(s) { | ||||||||||||||||||
t.Error("Expected false, got true from:", s) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
for _, s := range reject_sentences { | ||||||||||||||||||
if !tt.profanityDetector.IsProfane(s) { | ||||||||||||||||||
t.Error("Expected true, got false from:", s) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func TestFalseNegatives(t *testing.T) { | ||||||||||||||||||
sentences := []string{ | ||||||||||||||||||
"dumb ass", // ass -> bASS (FP) -> dumBASS (FFP) | ||||||||||||||||||
|
@@ -564,6 +594,10 @@ func TestFalseNegatives(t *testing.T) { | |||||||||||||||||
name: "With Custom Dictionary", | ||||||||||||||||||
profanityDetector: NewProfanityDetector().WithCustomDictionary(DefaultProfanities, DefaultFalsePositives, DefaultFalseNegatives), | ||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
name: "With Custom Dictionary", | ||||||||||||||||||
profanityDetector: NewProfanityDetector().WithCustomDictionary(DefaultProfanities, DefaultFalsePositives, DefaultFalseNegatives), | ||||||||||||||||||
}, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Was this a typo? It's a duplicate of the scenario above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I meant to have it include coverage of the new code by setting it to use exact words for one of them. pushed that fix in bf6efc8 |
||||||||||||||||||
} | ||||||||||||||||||
for _, tt := range tests { | ||||||||||||||||||
t.Run(tt.name, func(t *testing.T) { | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go uses camelCase instead of snake_case - could you make the changes to the other parts of your code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in bf6efc8, thank you! the perils of switching between languages and getting my styles mixed up 😅