From 2e16173c217c6201c226e48b38f350bfd377393e Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Sat, 19 Jun 2021 00:01:51 +0200 Subject: zippy: add test --- skate/schema.go | 5 +---- skate/zippy.go | 2 +- skate/zippy_test.go | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/skate/schema.go b/skate/schema.go index 6b335a3..af920ee 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -348,13 +348,10 @@ type BiblioRef struct { MatchReason string `json:"match_reason,omitempty"` TargetUnstructured string `json:"target_unstructured,omitempty"` TargetCSL string `json:"target_csl,omitempty"` - // Extra struct { - // Ref Ref `json:"ref,omitempty"` // keep the raw original ref around (e.g. for unmatched) - // } `json:"extra,omitempty"` } // Hash returns a string that will be the same, if source and target are -// equals; different otherwise. +// equal; different otherwise. This can be used to detect duplicate links. func (b *BiblioRef) LinkHash() string { switch { case b.SourceReleaseIdent != "" && b.TargetReleaseIdent != "": diff --git a/skate/zippy.go b/skate/zippy.go index 0d92873..2317b56 100644 --- a/skate/zippy.go +++ b/skate/zippy.go @@ -452,7 +452,7 @@ func uniqueMatches(docs []string, stats *statsAugment) (result []*BiblioRef, err } brefs = append(brefs, &bref) } - // Make sure exact matches come first. + // Make sure exact matches come first. XXX: bug? sort.Slice(brefs, func(i, j int) bool { return brefs[i].MatchStatus == StatusExact.Short() }) diff --git a/skate/zippy_test.go b/skate/zippy_test.go index 3e64dd0..f1e8822 100644 --- a/skate/zippy_test.go +++ b/skate/zippy_test.go @@ -129,6 +129,29 @@ func TestUniqueMatches(t *testing.T) { }}, err: nil, }, + { + about: "regression; a buggy sort?", + docs: []string{` + {"_id": "s1_0", + "source_release_ident": "s1", + "target_release_ident": "t1", + "match_status": "exact", + "match_reason": "a"}`, + `{"_id": "s1_1", + "source_release_ident": "s1", + "target_release_ident": "t1", + "match_status": "fuzzy", + "match_reason": "b"}`, + }, + result: []*BiblioRef{&BiblioRef{ + Key: "s1_0", + SourceReleaseIdent: "s1", + TargetReleaseIdent: "t1", + MatchStatus: "exact", + MatchReason: "a", + }}, + err: nil, + }, } for _, c := range cases { result, err := uniqueMatches(c.docs, &statsAugment{}) -- cgit v1.2.3