-
Notifications
You must be signed in to change notification settings - Fork 32
/
bytemap_test.go
53 lines (45 loc) · 1017 Bytes
/
bytemap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//nolint:testpackage
package bytemap
import (
"testing"
)
func TestByteMap(t *testing.T) {
var m ByteSliceMap[int]
//nolint:asciicheck
ಠ := []byte("fಠo")
m.Put(ಠ, 123)
m.PutString("foo", 456)
v1, ok1 := m.GetString("fಠo")
if !ok1 {
t.Error("GetString('fಠo') ok=false, want: true")
}
if v1 != 123 {
t.Errorf("GetString('fಠo')=%v, want: %v", v1, 123)
}
v2, ok2 := m.Get([]byte{'f', 'o', 'o'})
if !ok2 {
t.Error("Get('foo') ok=false, want: true")
}
//nolint: forcetypeassert
if v2 != 456 {
t.Errorf("Get('foo')=%v, want: %v", v2, 456)
}
}
func TestByteMapMissingValue(t *testing.T) {
var m ByteSliceMap[*string]
m.PutString("foo", nil)
v1, ok1 := m.GetString("fಠo")
if ok1 {
t.Error("GetString('fಠo') ok=true, want: false")
}
if v1 != nil {
t.Errorf("GetString('fಠo')=%v, want want nil", v1)
}
v2, ok2 := m.Get([]byte{'f', 'o', 'o'})
if !ok2 {
t.Error("Get('foo') ok=false, want: true")
}
if v2 != nil {
t.Errorf("Get('foo')=%v, want: nil", v2)
}
}