-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_error_test.go
68 lines (50 loc) · 1.05 KB
/
parse_error_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
59
60
61
62
63
64
65
66
67
68
package hype
import (
"errors"
"fmt"
"io"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_ParseError(t *testing.T) {
t.Parallel()
r := require.New(t)
oce := ParseError{
Err: io.EOF,
}
wrapped := fmt.Errorf("error: %w", oce)
r.True(oce.As(&ParseError{}), oce)
r.True(oce.Is(oce), oce)
r.True(oce.Unwrap() == io.EOF, oce)
var ce ParseError
r.True(errors.As(wrapped, &ce), wrapped)
ce = ParseError{}
r.True(errors.Is(wrapped, ce), wrapped)
err := errors.Unwrap(oce)
r.Equal(io.EOF, err)
}
func Test_ParseError_MarshalJSON(t *testing.T) {
t.Parallel()
pe := ParseError{
Contents: []byte("contents"),
Err: io.EOF,
Filename: "test.md",
Root: "root",
}
testJSON(t, "parse_error", pe)
}
func Test_ParseError_Error(t *testing.T) {
t.Parallel()
r := require.New(t)
pe := ParseError{
Contents: []byte("contents"),
Err: io.EOF,
Filename: "test.md",
Root: "root",
}
act := pe.Error()
act = strings.TrimSpace(act)
exp := "filepath: root/test.md\nparse error: EOF"
r.Equal(exp, act)
}