package detector import ( "reflect" "testing" ) func TestDetect(t *testing.T) { d := New([]string{"しょうもな", "たまげたなあ"}) got := d.Detect("いやしょうもな、たまげたなあ") want := []string{"しょうもな", "たまげたなあ"} if !reflect.DeepEqual(got, want) { t.Fatalf("Detect() = %v, want %v", got, want) } if got := d.Detect("普通のコメントです"); got != nil { t.Fatalf("Detect() = %v, want nil", got) } } func TestRedact(t *testing.T) { d := New([]string{"しょうもな"}) redacted, matched := d.Redact("それはしょうもな案件だ") if want := "それは○○○○○案件だ"; redacted != want { t.Fatalf("Redact() text = %q, want %q", redacted, want) } if want := []string{"しょうもな"}; !reflect.DeepEqual(matched, want) { t.Fatalf("Redact() matched = %v, want %v", matched, want) } } func TestNewDeduplicates(t *testing.T) { d := New([]string{"a", "a", " b ", "", "b"}) if got := d.phrases; !reflect.DeepEqual(got, []string{"a", "b"}) { t.Fatalf("phrases = %v, want [a b]", got) } }