File tree 4 files changed +93
-11
lines changed
4 files changed +93
-11
lines changed Original file line number Diff line number Diff line change @@ -2,21 +2,24 @@ name: Go
2
2
3
3
on :
4
4
push :
5
- branches : [ main ]
5
+ branches : [main]
6
6
pull_request :
7
- branches : [ main ]
7
+ branches : [main]
8
8
9
9
jobs :
10
10
e2e :
11
+ strategy :
12
+ matrix :
13
+ go-version : ["=1.18", "^1.23"]
11
14
runs-on : ubuntu-latest
12
15
steps :
13
- - uses : actions/checkout@v2
16
+ - uses : actions/checkout@v4
14
17
15
- - name : Set up Go
16
- uses : actions/setup-go@v2
17
- with :
18
- go-version : 1.18
18
+ - name : Set up Go
19
+ uses : actions/setup-go@v5
20
+ with :
21
+ go-version : ${{ matrix.go-version }}
19
22
20
- - name : Test
21
- run : |
22
- go test *.go
23
+ - name : Test
24
+ run : |
25
+ go test -v .
Original file line number Diff line number Diff line change @@ -208,7 +208,7 @@ func TestGetOrSet(t *testing.T) {
208
208
}
209
209
}
210
210
211
- func TestIterator (t * testing.T ) {
211
+ func TestForEach (t * testing.T ) {
212
212
m := New [int , * Animal ]()
213
213
214
214
m .ForEach (func (i int , a * Animal ) bool {
Original file line number Diff line number Diff line change
1
+ //go:build go1.23
2
+ // +build go1.23
3
+
4
+ package haxmap
5
+
6
+ import "iter"
7
+
8
+ func (m * Map [K , V ]) Iterator () iter.Seq2 [K , V ] {
9
+ return func (yield func (key K , value V ) bool ) {
10
+ for item := m .listHead .next (); item != nil ; item = item .next () {
11
+ if ! yield (item .key , * item .value .Load ()) {
12
+ return
13
+ }
14
+ }
15
+ }
16
+ }
17
+
18
+ func (m * Map [K , _ ]) Keys () iter.Seq [K ] {
19
+ return func (yield func (key K ) bool ) {
20
+ for item := m .listHead .next (); item != nil ; item = item .next () {
21
+ if ! yield (item .key ) {
22
+ return
23
+ }
24
+ }
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ //go:build go1.23
2
+ // +build go1.23
3
+
4
+ package haxmap
5
+
6
+ import (
7
+ "testing"
8
+ )
9
+
10
+ func TestIterators (t * testing.T ) {
11
+ type Value = struct {
12
+ key int
13
+ }
14
+
15
+ m := New [int , * Value ]()
16
+
17
+ itemCount := 16
18
+ for i := itemCount ; i > 0 ; i -- {
19
+ m .Set (i , & Value {i })
20
+ }
21
+
22
+ t .Run ("iterator" , func (t * testing.T ) {
23
+ counter := 0
24
+ for k , v := range m .Iterator () {
25
+ if v == nil {
26
+ t .Error ("Expecting an object." )
27
+ } else if k != v .key {
28
+ t .Error ("Incorrect key/value pairs" )
29
+ }
30
+
31
+ counter ++
32
+ }
33
+
34
+ if counter != itemCount {
35
+ t .Error ("Iterated item count did not match." )
36
+ }
37
+ })
38
+
39
+ t .Run ("keys" , func (t * testing.T ) {
40
+ counter := 0
41
+ for k := range m .Keys () {
42
+ _ , ok := m .Get (k )
43
+ if ! ok {
44
+ t .Error ("The key is not is the map" )
45
+ }
46
+ counter ++
47
+ }
48
+
49
+ if counter != itemCount {
50
+ t .Error ("Iterated item count did not match." )
51
+ }
52
+ })
53
+ }
You can’t perform that action at this time.
0 commit comments