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