40 lines
948 B
Go
40 lines
948 B
Go
package keywords
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestEnsureFileExistsCreatesMissingParentDirectory(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "nested", "words.txt")
|
|
|
|
if err := ensureFileExists(path, "hello\n"); err != nil {
|
|
t.Fatalf("ensureFileExists returned error: %v", err)
|
|
}
|
|
|
|
content, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatalf("read created file: %v", err)
|
|
}
|
|
if got := string(content); got != "hello\n" {
|
|
t.Fatalf("unexpected file content: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestFilterCleanRemovesKeywordsWithoutBreakingWordBoundaries(t *testing.T) {
|
|
filter := &Filter{
|
|
words: []string{"[spam]", "VIP"},
|
|
trash: map[string]struct{}{},
|
|
}
|
|
|
|
if got := filter.Clean("Movie [spam] Title", false); got != "Movie Title" {
|
|
t.Fatalf("Clean() = %q, want %q", got, "Movie Title")
|
|
}
|
|
|
|
if got := filter.Clean("VIP Movie", false); got != "Movie" {
|
|
t.Fatalf("Clean() = %q, want %q", got, "Movie")
|
|
}
|
|
}
|