-
Notifications
You must be signed in to change notification settings - Fork 18
/
jsonvalue_internal_test.go
48 lines (37 loc) · 1.26 KB
/
jsonvalue_internal_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
package jsonvalue
import "testing"
func testInternal(t *testing.T) {
cv("test predict numbers", func() { testInternalPredict(t) })
}
func testInternalPredict(t *testing.T) {
const maxUint32 = 0xFFFFFFFF
v := internal.predict.calcStorage
p := internal.predict.bytesPerValue
defer func(v uint64, p uint64) {
// cancel mocking
internal.predict.calcStorage = v
internal.predict.bytesPerValue = p
}(v, p)
size := internalLoadPredictSizePerValue()
t.Logf("total: %d, count %d, calculated per size: %d", v>>32, v&maxUint32, size)
so(size, eq, (v>>32)/(v&maxUint32))
var mockTotal uint64 = maxUint32
var mockCount uint64 = maxUint32 / 16
internal.predict.calcStorage = (mockTotal << 32) + mockCount
internal.predict.bytesPerValue = 0
size = internalLoadPredictSizePerValue()
so(size, eq, 16)
// try unmarshal a new jsonvalue, which will make total overflowing uint32
const raw = `1234567890123456`
so(len(raw), eq, 16)
jv, err := UnmarshalString(raw)
so(err, isNil)
so(jv.String(), eq, raw)
size = internalLoadPredictSizePerValue()
so(size, eq, 16)
v = internal.predict.calcStorage
p = internal.predict.bytesPerValue
t.Logf("total: %d, count %d, calculated per size: %d", v>>32, v&maxUint32, size)
so(size, eq, (v>>32)/(v&maxUint32))
so(size, eq, p)
}