json_test.go 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package errors
  2. import (
  3. "encoding/json"
  4. "regexp"
  5. "testing"
  6. )
  7. func TestFrameMarshalText(t *testing.T) {
  8. var tests = []struct {
  9. Frame
  10. want string
  11. }{{
  12. initpc,
  13. `^github.com/pkg/errors\.init(\.ializers)? .+/github\.com/pkg/errors/stack_test.go:\d+$`,
  14. }, {
  15. 0,
  16. `^unknown$`,
  17. }}
  18. for i, tt := range tests {
  19. got, err := tt.Frame.MarshalText()
  20. if err != nil {
  21. t.Fatal(err)
  22. }
  23. if !regexp.MustCompile(tt.want).Match(got) {
  24. t.Errorf("test %d: MarshalJSON:\n got %q\n want %q", i+1, string(got), tt.want)
  25. }
  26. }
  27. }
  28. func TestFrameMarshalJSON(t *testing.T) {
  29. var tests = []struct {
  30. Frame
  31. want string
  32. }{{
  33. initpc,
  34. `^"github\.com/pkg/errors\.init(\.ializers)? .+/github\.com/pkg/errors/stack_test.go:\d+"$`,
  35. }, {
  36. 0,
  37. `^"unknown"$`,
  38. }}
  39. for i, tt := range tests {
  40. got, err := json.Marshal(tt.Frame)
  41. if err != nil {
  42. t.Fatal(err)
  43. }
  44. if !regexp.MustCompile(tt.want).Match(got) {
  45. t.Errorf("test %d: MarshalJSON:\n got %q\n want %q", i+1, string(got), tt.want)
  46. }
  47. }
  48. }