-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmap_test.go
59 lines (50 loc) · 1.21 KB
/
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
package gates
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMapToNative(t *testing.T) {
a := map[string]Value{
"foo": Int(42),
}
b := Map(a)
a["bar"] = b
x := b.ToNative().(map[string]interface{})
assert.Equal(t, int64(42), x["foo"])
assert.Equal(t, x, x["bar"])
assert.Equal(t, map[string]interface{}(nil), Map(nil).ToNative())
}
func TestMapToNativeCircular(t *testing.T) {
a := map[string]Value{
"foo": Int(42),
}
b := Map(a)
a["bar"] = b
x := b.ToNative(SkipCircularReference).(map[string]interface{})
assert.Nil(t, x["bar"])
}
func TestMapIterator(t *testing.T) {
m := Map(map[string]Value{})
it := m.Iterator()
value, ok := it.Next()
assert.Equal(t, Null, value)
assert.False(t, ok)
m = Map(map[string]Value{"foo": Int(42), "bar": String("baz"), "deleted": Bool(true)})
it = m.Iterator()
value, ok = it.Next()
assert.Equal(t, Map(map[string]Value{
"key": String("bar"),
"value": String("baz"),
}), value)
assert.True(t, ok)
delete(m, "deleted")
value, ok = it.Next()
assert.Equal(t, Map(map[string]Value{
"key": String("foo"),
"value": Int(42),
}), value)
assert.True(t, ok)
value, ok = it.Next()
assert.Equal(t, Null, value)
assert.False(t, ok)
}