52 lines
963 B
Go
52 lines
963 B
Go
package errors
|
|
|
|
import (
|
|
"encoding/json"
|
|
"regexp"
|
|
"testing"
|
|
)
|
|
|
|
func TestFrameMarshalText(t *testing.T) {
|
|
var tests = []struct {
|
|
Frame
|
|
want string
|
|
}{{
|
|
initpc,
|
|
`^game/errors\.init(\.ializers)? .+/game/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,
|
|
`^"game/errors\.init(\.ializers)? .+/game/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)
|
|
}
|
|
}
|
|
}
|