...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ociunify
16
17 import (
18 "testing"
19
20 "cuelabs.dev/go/oci/ociregistry"
21 "github.com/go-quicktest/qt"
22 )
23
24 var mergeIterTests = []struct {
25 testName string
26 it0, it1 ociregistry.Seq[int]
27 want []int
28 wantErr error
29 }{{
30 testName: "IdenticalContents",
31 it0: ociregistry.SliceIter([]int{1, 2, 3}),
32 it1: ociregistry.SliceIter([]int{1, 2, 3}),
33 want: []int{1, 2, 3},
34 }, {
35 testName: "DifferentContents",
36 it0: ociregistry.SliceIter([]int{0, 1, 2, 3}),
37 it1: ociregistry.SliceIter([]int{1, 2, 3, 5}),
38 want: []int{0, 1, 2, 3, 5},
39 }, {
40 testName: "NoItems",
41 it0: ociregistry.SliceIter[int](nil),
42 it1: ociregistry.SliceIter[int](nil),
43 want: []int{},
44 }}
45
46 func TestMergeIter(t *testing.T) {
47 for _, test := range mergeIterTests {
48 t.Run(test.testName, func(t *testing.T) {
49 it := mergeIter(test.it0, test.it1, cmpInt)
50 xs, err := ociregistry.All(it)
51 qt.Assert(t, qt.DeepEquals(xs, test.want))
52 qt.Assert(t, qt.Equals(err, test.wantErr))
53 })
54 }
55 }
56
57 func cmpInt(i, j int) int {
58 if i < j {
59 return -1
60 }
61 if i > j {
62 return 1
63 }
64 return 0
65 }
66
View as plain text