-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_cache_test.go
47 lines (37 loc) · 1.04 KB
/
encode_cache_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
package qs
import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestCacheStore(t *testing.T) {
test := assert.New(t)
s := &basicVal{}
cacheStore := newCacheStore()
test.NotNil(cacheStore)
fields := cachedFields{&float64Field{}}
cacheStore.Store(reflect.TypeOf(s), fields)
cachedFlds := cacheStore.Retrieve(reflect.TypeOf(s))
test.NotNil(cachedFlds)
test.Len(cachedFlds, len(fields))
test.True(&fields[0] == &cachedFlds[0])
}
func TestNewCacheField(t *testing.T) {
test := assert.New(t)
name := []byte(`abc`)
opts := [][]byte{[]byte(`omitempty`)}
cacheField := newCachedFieldByKind(reflect.ValueOf("").Kind(), name, opts)
if stringField, ok := cacheField.(*stringField); ok {
test.Equal(string(name), stringField.name)
test.True(stringField.omitEmpty)
} else {
test.FailNow("")
}
test.IsType(&stringField{}, cacheField)
}
func TestNewCacheField2(t *testing.T) {
test := assert.New(t)
var strPtr *string
cacheField := newCachedFieldByKind(reflect.ValueOf(strPtr).Kind(), nil, nil)
test.Nil(cacheField)
}