github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/natives/src/go/doc/doc_test.go (about) 1 //go:build js 2 3 package doc 4 5 import ( 6 "fmt" 7 "testing" 8 ) 9 10 func compareSlices(t *testing.T, name string, got, want interface{}, compareElem interface{}) { 11 // TODO(nevkontakte): Remove this override after generics are supported. 12 // https://github.com/gopherjs/gopherjs/issues/1013. 13 switch got.(type) { 14 case []*Func: 15 got := got.([]*Func) 16 want := want.([]*Func) 17 compareElem := compareElem.(func(t *testing.T, msg string, got, want *Func)) 18 if len(got) != len(want) { 19 t.Errorf("%s: got %d, want %d", name, len(got), len(want)) 20 } 21 for i := 0; i < len(got) && i < len(want); i++ { 22 compareElem(t, fmt.Sprintf("%s[%d]", name, i), got[i], want[i]) 23 } 24 case []*Type: 25 got := got.([]*Type) 26 want := want.([]*Type) 27 compareElem := compareElem.(func(t *testing.T, msg string, got, want *Type)) 28 if len(got) != len(want) { 29 t.Errorf("%s: got %d, want %d", name, len(got), len(want)) 30 } 31 for i := 0; i < len(got) && i < len(want); i++ { 32 compareElem(t, fmt.Sprintf("%s[%d]", name, i), got[i], want[i]) 33 } 34 default: 35 t.Errorf("unexpected argument type %T", got) 36 } 37 }