summaryrefslogtreecommitdiff
path: root/internal/engine/match_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-17 10:15:45 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-17 10:15:45 +0200
commita2cb20851499e9c00bd3bf642680a9ce3148cae8 (patch)
tree09ef80b9662308b758a88ed2f43078c92e525f29 /internal/engine/match_test.go
parent47b6776c2cb9b017ad95acb5aae8e34b8776fc7c (diff)
downloadkrino-a2cb20851499e9c00bd3bf642680a9ce3148cae8.tar.gz
krino-a2cb20851499e9c00bd3bf642680a9ce3148cae8.zip
gui: name the other copy of a duplicate, and offer to keep this one instead
Diffstat (limited to 'internal/engine/match_test.go')
-rw-r--r--internal/engine/match_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/engine/match_test.go b/internal/engine/match_test.go
index 63bb54a..224f881 100644
--- a/internal/engine/match_test.go
+++ b/internal/engine/match_test.go
@@ -460,3 +460,37 @@ func TestRuleDuplicateWarningShortensThePath(t *testing.T) {
t.Errorf("no shortened rule warning for a.txt: %+v %+v", r.Matched, r.Unmatched)
}
}
+
+// TestFileMatchNamesTheDuplicate: a file a (duplicate) test matched comes
+// back with the other copy's absolute path, so a front end can say where it
+// is and act on it - the reason text alone says "duplicate of NAME" for a
+// copy inside the directory, which reads as no place at all (plan 21).
+func TestFileMatchNamesTheDuplicate(t *testing.T) {
+ e, d, _ := fixture(t)
+ res, err := e.Match(context.Background(), d)
+ if err != nil {
+ t.Fatal(err)
+ }
+ found := false
+ for _, fm := range res.Matched {
+ if fm.File.Rel != "report (1).pdf" && fm.File.Rel != "report.pdf" {
+ continue
+ }
+ if fm.DuplicateOf == "" {
+ continue
+ }
+ found = true
+ if !filepath.IsAbs(fm.DuplicateOf) {
+ t.Errorf("%s: DuplicateOf = %q, want an absolute path", fm.File.Rel, fm.DuplicateOf)
+ }
+ if fm.DuplicateOf == fm.File.Path {
+ t.Errorf("%s: reported as a duplicate of itself", fm.File.Rel)
+ }
+ if _, err := os.Stat(fm.DuplicateOf); err != nil {
+ t.Errorf("%s: DuplicateOf does not exist: %v", fm.File.Rel, err)
+ }
+ }
+ if !found {
+ t.Fatal("neither copy came back with the file it duplicates")
+ }
+}