forked from go-faster/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jx_test.go
48 lines (44 loc) · 842 Bytes
/
jx_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 jx
import (
"bytes"
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPutEncoder(t *testing.T) {
var wg sync.WaitGroup
for j := 0; j < 4; j++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1024; i++ {
e := GetEncoder()
e.RawStr("false")
assert.Equal(t, "false", e.String())
PutEncoder(e)
}
}()
}
wg.Wait()
}
func TestPutDecoder(t *testing.T) {
var wg sync.WaitGroup
for j := 0; j < 4; j++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1024; i++ {
d := GetDecoder()
assert.Equal(t, d.Next(), Invalid)
d.Reset(bytes.NewBufferString("false"))
assert.Equal(t, d.Next(), Bool)
v, err := d.Bool()
assert.NoError(t, err)
assert.Equal(t, d.Next(), Invalid)
assert.False(t, v)
PutDecoder(d)
}
}()
}
wg.Wait()
}