This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add json.Marshaler support to the Frame type. (#197)
* Add json.Marshaler support to the Frame type. * Update regex for Go tip * Escape periods in regular expression tests * Implement encoding.TextMarshaler instead of json.Marshaler
- Loading branch information
1 parent
ffb6e22
commit 856c240
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters