forked from pkg/errors
-
Notifications
You must be signed in to change notification settings - Fork 6
/
json_test.go
51 lines (48 loc) · 1.01 KB
/
json_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 errors
import (
"encoding/json"
"regexp"
"testing"
)
func TestFrameMarshalText(t *testing.T) {
var tests = []struct {
Frame
want string
}{{
initpc,
`^github.com/friendsofgo/errors\.init(\.ializers)? .+/github\.com/friendsofgo/errors/stack_test.go:\d+$`,
}, {
0,
`^unknown$`,
}}
for i, tt := range tests {
got, err := tt.Frame.MarshalText()
if err != nil {
t.Fatal(err)
}
if !regexp.MustCompile(tt.want).Match(got) {
t.Errorf("test %d: MarshalJSON:\n got %q\n want %q", i+1, string(got), tt.want)
}
}
}
func TestFrameMarshalJSON(t *testing.T) {
var tests = []struct {
Frame
want string
}{{
initpc,
`^"github\.com/friendsofgo/errors\.init(\.ializers)? .+/github\.com/friendsofgo/errors/stack_test.go:\d+"$`,
}, {
0,
`^"unknown"$`,
}}
for i, tt := range tests {
got, err := json.Marshal(tt.Frame)
if err != nil {
t.Fatal(err)
}
if !regexp.MustCompile(tt.want).Match(got) {
t.Errorf("test %d: MarshalJSON:\n got %q\n want %q", i+1, string(got), tt.want)
}
}
}