2020-10-20 07:07:35 +02:00
|
|
|
// Copyright 2020 Frédéric Guillot. All rights reserved.
|
2020-10-16 23:40:56 +02:00
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package processor // import "miniflux.app/reader/processor"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-20 07:07:35 +02:00
|
|
|
"miniflux.app/model"
|
|
|
|
)
|
2020-10-16 23:40:56 +02:00
|
|
|
|
2020-10-20 07:07:35 +02:00
|
|
|
func TestBlockingEntries(t *testing.T) {
|
|
|
|
var scenarios = []struct {
|
|
|
|
feed *model.Feed
|
|
|
|
entry *model.Entry
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{&model.Feed{ID: 1, BlocklistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
|
|
|
|
{&model.Feed{ID: 1, BlocklistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
|
|
|
|
{&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, false},
|
2020-10-16 23:40:56 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 07:07:35 +02:00
|
|
|
for _, tc := range scenarios {
|
|
|
|
result := isBlockedEntry(tc.feed, tc.entry)
|
|
|
|
if tc.expected != result {
|
|
|
|
t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
|
|
|
|
}
|
2020-10-16 23:40:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 07:07:35 +02:00
|
|
|
func TestAllowEntries(t *testing.T) {
|
|
|
|
var scenarios = []struct {
|
|
|
|
feed *model.Feed
|
|
|
|
entry *model.Entry
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
|
|
|
|
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
|
|
|
|
{&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, true},
|
2020-10-16 23:40:56 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 07:07:35 +02:00
|
|
|
for _, tc := range scenarios {
|
|
|
|
result := isAllowedEntry(tc.feed, tc.entry)
|
|
|
|
if tc.expected != result {
|
|
|
|
t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
|
|
|
|
}
|
2020-10-16 23:40:56 +02:00
|
|
|
}
|
|
|
|
}
|