-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathordered_map_test.go
129 lines (109 loc) · 2.18 KB
/
ordered_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package orderedmap
import (
"testing"
"github.com/alecthomas/assert/v2"
)
func TestOrderedMap_Has(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
assert.True(t, m.Has("name"))
assert.True(t, m.Has("age"))
assert.False(t, m.Has("active"))
}
func TestOrderedMap_Get(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
{
v, ok := m.Get("name")
assert.True(t, ok)
assert.Equal(t, "John", v)
}
{
v, ok := m.Get("age")
assert.True(t, ok)
assert.Equal(t, 30, v)
}
{
_, ok := m.Get("active")
assert.False(t, ok)
}
}
func TestOrderedMap_Set(t *testing.T) {
m := OrderedMap[string, any]{}
m.Set("name", "John")
m.Set("age", 30)
assert.Equal(t, OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}, m)
}
func TestOrderedMap_Delete(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
m.Delete("name")
assert.Equal(t, OrderedMap[string, any]{
{"age", 30},
}, m)
}
func TestOrderedMap_Keys(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
assert.Equal(t, []string{"name", "age"}, m.Keys())
}
func TestOrderedMap_Values(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
assert.Equal(t, []any{"John", 30}, m.Values())
}
func TestOrderedMap_Clear(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
m.Clear()
assert.Equal(t, OrderedMap[string, any]{}, m)
}
func TestOrderedMap_Clone(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
c := m.Clone()
assert.Equal(t, m, c)
c.Set("name", "Jane")
assert.NotEqual(t, m, c)
}
func TestOrderedMap_Equal(t *testing.T) {
m1 := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
m2 := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
assert.True(t, m1.Equal(m2))
m2.Set("name", "Jane")
assert.False(t, m1.Equal(m2))
}
func TestOrderedMap_DeepCopyInto(t *testing.T) {
m := OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
}
var c OrderedMap[string, any]
m.DeepCopyInto(&c)
assert.Equal(t, m, c)
c.Set("name", "Jane")
assert.NotEqual(t, m, c)
}