forked from gobuffalo/packr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox_map_test.go
55 lines (39 loc) · 901 Bytes
/
box_map_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
54
55
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package packr
import (
"sort"
"testing"
"github.com/stretchr/testify/require"
)
func Test_boxMap(t *testing.T) {
r := require.New(t)
sm := &boxMap{}
sm.Store("a", New(`test-a`, ``))
s, ok := sm.Load("a")
r.True(ok)
r.Equal(New(`test-a`, ``), s)
s, ok = sm.LoadOrStore("b", New(`test-b`, ``))
r.True(ok)
r.Equal(New(`test-b`, ``), s)
s, ok = sm.LoadOrStore("b", New(`test-bb`, ``))
r.True(ok)
r.Equal(New(`test-b`, ``), s)
var keys []string
sm.Range(func(key string, value *Box) bool {
keys = append(keys, key)
return true
})
sort.Strings(keys)
r.Equal(sm.Keys(), keys)
sm.Delete("b")
r.Equal([]string{"a", "b"}, keys)
sm.Delete("b")
_, ok = sm.Load("b")
r.False(ok)
func(m *boxMap) {
m.Store("c", New(`test-c`, ``))
}(sm)
s, ok = sm.Load("c")
r.True(ok)
r.Equal(New(`test-c`, ``), s)
}