Skip to content

Commit e1c8578

Browse files
authored
Merge pull request #1349 from ydb-platform/fix-build-go1.20
Fixed build for go1.20
2 parents 099075b + d1d6658 commit e1c8578

File tree

7 files changed

+114
-25
lines changed

7 files changed

+114
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed build for go1.20
2+
13
## v3.75.1
24
* Fixed return more than one row error if real error raised on try read next row
35
* Fixed checking errors for session must be deleted

internal/xslices/diff_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,59 @@ func TestDiff(t *testing.T) {
6161
},
6262
dropped: []int{},
6363
},
64+
{
65+
name: "OnlyAddedWithDuplicatesInPrevious",
66+
previous: []int{
67+
1,
68+
0,
69+
1,
70+
3,
71+
},
72+
newest: []int{
73+
1,
74+
3,
75+
2,
76+
0,
77+
},
78+
steady: []int{
79+
0,
80+
1,
81+
3,
82+
},
83+
added: []int{
84+
2,
85+
},
86+
dropped: []int{
87+
1,
88+
},
89+
},
90+
{
91+
name: "OnlyAddedWithDuplicatesInNewest",
92+
previous: []int{
93+
1,
94+
0,
95+
3,
96+
},
97+
newest: []int{
98+
1,
99+
1,
100+
3,
101+
1,
102+
2,
103+
0,
104+
},
105+
steady: []int{
106+
0,
107+
1,
108+
3,
109+
},
110+
added: []int{
111+
1,
112+
1,
113+
2,
114+
},
115+
dropped: []int{},
116+
},
64117
{
65118
name: "OnlyDropped",
66119
previous: []int{
@@ -132,6 +185,34 @@ func TestDiff(t *testing.T) {
132185
3,
133186
},
134187
},
188+
{
189+
name: "AddedWithDuplicates",
190+
previous: []int{
191+
1,
192+
3,
193+
3,
194+
0,
195+
},
196+
newest: []int{
197+
4,
198+
7,
199+
7,
200+
8,
201+
},
202+
steady: []int{},
203+
added: []int{
204+
4,
205+
7,
206+
7,
207+
8,
208+
},
209+
dropped: []int{
210+
0,
211+
1,
212+
3,
213+
3,
214+
},
215+
},
135216
} {
136217
t.Run(tt.name, func(t *testing.T) {
137218
steady, added, dropped := Diff(tt.previous, tt.newest, func(lhs, rhs int) int {

internal/xslices/sort.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ import (
77
"slices"
88
)
99

10-
func SortCopy[T any](in []T, cmp func(lhs, rhs T) int) (out []T) {
11-
out = Clone(in)
12-
13-
Sort(out, cmp)
14-
15-
return out
16-
}
17-
1810
func Sort[T any](in []T, cmp func(lhs, rhs T) int) {
1911
slices.SortFunc(in, cmp)
2012
}

internal/xslices/sort_copy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package xslices
2+
3+
func SortCopy[T any](in []T, cmp func(lhs, rhs T) int) (out []T) {
4+
out = Clone(in)
5+
6+
Sort(out, cmp)
7+
8+
return out
9+
}

internal/xslices/sort_copy_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package xslices
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestSortCopy(t *testing.T) {
10+
src := []int{3, 2, 1}
11+
dst := SortCopy(src, func(lhs, rhs int) int {
12+
return lhs - rhs
13+
})
14+
require.Equal(t, len(src), len(dst))
15+
require.NotEqual(t, src, dst)
16+
require.Equal(t, []int{3, 2, 1}, src)
17+
require.Equal(t, []int{1, 2, 3}, dst)
18+
}

internal/xslices/sort_go1.20.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ import (
77
"sort"
88
)
99

10-
func SortCopy[T any](in []T, cmp func(lhs, rhs T) int) (out []T) {
11-
out = Clone(in)
12-
13-
Sort(out, func(i, j int) bool {
14-
return cmp(out[i], out[j]) < 0
15-
})
16-
17-
return out
18-
}
19-
2010
func Sort[T any](in []T, cmp func(lhs, rhs T) int) {
2111
sort.Slice(in, func(i, j int) bool {
2212
return cmp(in[i], in[j]) < 0

internal/xslices/sort_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import (
66
"github.com/stretchr/testify/require"
77
)
88

9-
func TestSortCopy(t *testing.T) {
10-
src := []int{3, 2, 1}
11-
dst := SortCopy(src, func(lhs, rhs int) int {
9+
func TestSort(t *testing.T) {
10+
ints := []int{1, 3, 2, 1}
11+
Sort(ints, func(lhs, rhs int) int {
1212
return lhs - rhs
1313
})
14-
require.Equal(t, len(src), len(dst))
15-
require.NotEqual(t, src, dst)
16-
require.Equal(t, []int{3, 2, 1}, src)
17-
require.Equal(t, []int{1, 2, 3}, dst)
14+
require.Equal(t, []int{1, 1, 2, 3}, ints)
1815
}

0 commit comments

Comments
 (0)