diff options
Diffstat (limited to 'internal/engine/exclude_test.go')
| -rw-r--r-- | internal/engine/exclude_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/engine/exclude_test.go b/internal/engine/exclude_test.go index 9aafd7f..3398b07 100644 --- a/internal/engine/exclude_test.go +++ b/internal/engine/exclude_test.go @@ -512,3 +512,39 @@ func TestExplainAgreesWithMatchOnADuplicateExclude(t *testing.T) { } } } + +// TestNotMatchedAfterAnUnknownRuleDoesNotAct: a partly read document an +// earlier content rule could not decide is not caught by a later +// (not (matched)) catch-all (plan 11 review L6). +func TestNotMatchedAfterAnUnknownRuleDoesNotAct(t *testing.T) { + h, dl := excludeTree(t, map[string]string{}) + os.MkdirAll(dl, 0o755) + partDocx(t, filepath.Join(dl, "part.docx"), "good body text") + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": ` +(path "~/dl") +(rule "acme" (when (content "acme ltd")) (move "Acme")) +(rule "rest" (when (not (matched))) (move "Unsorted")) +`}) + e, errs := Load(main) + if len(errs) > 0 { + t.Fatal(errs) + } + r, err := e.Match(context.Background(), e.Dirs[0]) + if err != nil { + t.Fatal(err) + } + for _, fm := range r.Matched { + if fm.File.Rel == "part.docx" { + t.Errorf("part.docx matched %d rules; the catch-all must not take a file an earlier rule could not decide", len(fm.Rules)) + } + } + x, err := e.Explain(context.Background(), filepath.Join(dl, "part.docx")) + if err != nil { + t.Fatal(err) + } + for _, rt := range x.Rules { + if rt.Match { + t.Errorf("explain: rule %s matches", rt.Rule.Name) + } + } +} |
