-
Notifications
You must be signed in to change notification settings - Fork 2
/
standard_like_test.go
51 lines (47 loc) · 1.04 KB
/
standard_like_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
package jzon
import (
"errors"
"io"
"strings"
"testing"
"testing/iotest"
"github.com/stretchr/testify/require"
)
func TestUnmarshalFromReader(t *testing.T) {
t.Run("success", func(t *testing.T) {
r := strings.NewReader("{}")
var i interface{}
err := UnmarshalFromReader(r, &i)
require.NoError(t, err)
})
t.Run("failure", func(t *testing.T) {
r := iotest.TimeoutReader(iotest.OneByteReader(strings.NewReader("{}")))
var i interface{}
err := UnmarshalFromReader(r, &i)
checkError(t, iotest.ErrTimeout, err)
})
t.Run("final error", func(t *testing.T) {
e := errors.New("test")
r := &stepByteReader{
b: "{}",
err: e,
}
var i interface{}
err := UnmarshalFromReader(r, &i)
checkError(t, e, err)
})
}
func TestUnmarshalFromString(t *testing.T) {
t.Run("success", func(t *testing.T) {
s := "{}"
var i interface{}
err := UnmarshalFromString(s, &i)
require.NoError(t, err)
})
t.Run("failure", func(t *testing.T) {
s := "{"
var i interface{}
err := UnmarshalFromString(s, &i)
checkError(t, io.EOF, err)
})
}