diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-06-12 01:19:00 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-06-12 01:19:00 +0200 |
commit | 18b938ff7aac1cef21de05ebd3671ab90b063c87 (patch) | |
tree | 7a491ec71d528a5cad86d462ad73a446b8d960f1 /skate | |
parent | 9e30f6769db7dc1ac90a090ff1c7e0cffd13e6e7 (diff) | |
download | refcat-18b938ff7aac1cef21de05ebd3671ab90b063c87.tar.gz refcat-18b938ff7aac1cef21de05ebd3671ab90b063c87.zip |
add tests
Diffstat (limited to 'skate')
-rw-r--r-- | skate/cmd/skate-reduce/main.go | 9 | ||||
-rw-r--r-- | skate/zippy.go | 11 | ||||
-rw-r--r-- | skate/zippy_test.go | 69 |
3 files changed, 84 insertions, 5 deletions
diff --git a/skate/cmd/skate-reduce/main.go b/skate/cmd/skate-reduce/main.go index fbb4f57..a1aaebe 100644 --- a/skate/cmd/skate-reduce/main.go +++ b/skate/cmd/skate-reduce/main.go @@ -78,6 +78,7 @@ var ( logFile = flag.String("log", "", "log filename") // Possible inputs -- we could switch to a subcommand cli parser? + bref = flag.String("B", "", "path to bref file") refs = flag.String("F", "", "path to refs input") releases = flag.String("L", "", "path to release input") wiki = flag.String("W", "", "path to wiki input") @@ -181,6 +182,14 @@ func main() { if err := skate.ZippyExactReleases(o, f, r, bw); err != nil { log.Fatal(err) } + case "unmatched": + b, r, err := xio.OpenTwo(*bref, *refs) + if err != nil { + log.Fatal(err) + } + if err := skate.ZippyBrefAugment(b, r, bw); err != nil { + log.Fatal(err) + } default: log.Fatalf("invalid mode") } diff --git a/skate/zippy.go b/skate/zippy.go index 7aff7a6..152e93f 100644 --- a/skate/zippy.go +++ b/skate/zippy.go @@ -313,10 +313,11 @@ func ZippyVerifyRefsOpenLibrary(olr, refs io.Reader, w io.Writer) error { return zipper.Run() } -// ZippyBrefAugment takes all matched elements from bref and adds docs from raw +// ZippyBrefAugment takes all matched docs from bref and adds docs from raw // refs, which have not been matched. It also gets rid of duplicate matches. // -// We can identify, which docs have been matched by checking the ref key and index. +// We can identify, which docs have been matched by checking the source ident, +// ref index and key. func ZippyBrefAugment(bref, raw io.Reader, w io.Writer) error { var ( enc = json.NewEncoder(w) @@ -357,8 +358,8 @@ func ZippyBrefAugment(bref, raw io.Reader, w io.Writer) error { // matchedRefsExtend takes a set of (unique) biblioref docs and will emit that // set of biblioref docs (unchanged) plus raw references as biblioref, which -// did not result in a match (determined by ref key and index). -func matchedRefsExtend(matched []*BiblioRef, refs []*Ref) { +// did not result in a match (determined by e.g. ref key and index). +func matchedRefsExtend(matched []*BiblioRef, refs []*Ref) []*BiblioRef { s := set.New() // store key + index of matched items for _, m := range matched { s.Add(m.Key + fmt.Sprintf("%d", m.RefIndex)) @@ -381,7 +382,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref) { bref.MatchReason = ReasonUnknown.Short() matched = append(matched, &bref) } - return + return matched } // uniqueMatches takes a list of bref docs (unserialized) and will return a diff --git a/skate/zippy_test.go b/skate/zippy_test.go index 84c878f..746bca4 100644 --- a/skate/zippy_test.go +++ b/skate/zippy_test.go @@ -103,3 +103,72 @@ func TestUniqueMatches(t *testing.T) { } } } + +func TestMatchedRefsExtend(t *testing.T) { + var cases = []struct { + matched []*BiblioRef + refs []*Ref + result []*BiblioRef + }{ + { + matched: []*BiblioRef{}, + refs: []*Ref{}, + result: []*BiblioRef{}, + }, + { + matched: []*BiblioRef{ + &BiblioRef{ + RefIndex: 2, + RefKey: "K2", + }, + }, + refs: []*Ref{}, + result: []*BiblioRef{ + &BiblioRef{ + RefIndex: 2, + RefKey: "K2", + }, + }, + }, + { + matched: []*BiblioRef{ + &BiblioRef{ + SourceReleaseIdent: "pud5shsflfgrth77lmlernavjm", + RefIndex: 2, + RefKey: "K2", + }, + }, + refs: []*Ref{ + &Ref{ + Biblio: Biblio{ + Title: "Title", + }, + Index: 3, + Key: "K3", + }, + }, + result: []*BiblioRef{ + &BiblioRef{ + SourceReleaseIdent: "pud5shsflfgrth77lmlernavjm", + RefIndex: 2, + RefKey: "K2", + }, + &BiblioRef{ + Key: "_3", + RefIndex: 3, + RefKey: "K3", + MatchStatus: StatusUnmatched.Short(), + MatchReason: ReasonUnknown.Short(), + SourceYear: "0", + }, + }, + }, + } + for _, c := range cases { + result := matchedRefsExtend(c.matched, c.refs) + if !reflect.DeepEqual(result, c.result) { + t.Logf("got %v", pretty.Diff(result, c.result)) + t.Fatalf("got %v, want %v", result, c.result) + } + } +} |