-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjx_test.go
58 lines (53 loc) · 1.12 KB
/
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
49
50
51
52
53
54
55
56
57
58
package jx
import (
"bytes"
"encoding/json"
"sync"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// requireCompat fails if `encoding/json` will encode v differently than exp.
func requireCompat(t testing.TB, got []byte, v interface{}) {
t.Helper()
buf, err := json.Marshal(v)
require.NoError(t, err)
require.Equal(t, string(buf), string(got))
}
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()
}