| 12 | ) |
| 13 | |
| 14 | func TestStringify(t *testing.T) { |
| 15 | t.Parallel() |
| 16 | var nilPointer *string |
| 17 | |
| 18 | tests := []struct { |
| 19 | in any |
| 20 | out string |
| 21 | }{ |
| 22 | // basic types |
| 23 | {"foo", `"foo"`}, |
| 24 | {123, `123`}, |
| 25 | {1.5, `1.5`}, |
| 26 | {false, `false`}, |
| 27 | { |
| 28 | []string{"a", "b"}, |
| 29 | `["a" "b"]`, |
| 30 | }, |
| 31 | { |
| 32 | struct { |
| 33 | A []string |
| 34 | }{nil}, |
| 35 | // nil slice is skipped |
| 36 | `{}`, |
| 37 | }, |
| 38 | { |
| 39 | struct { |
| 40 | A string |
| 41 | }{"foo"}, |
| 42 | // structs not of a named type get no prefix |
| 43 | `{A:"foo"}`, |
| 44 | }, |
| 45 | |
| 46 | // pointers |
| 47 | {nilPointer, `<nil>`}, |
| 48 | {Ptr("foo"), `"foo"`}, |
| 49 | {Ptr(123), `123`}, |
| 50 | {Ptr(false), `false`}, |
| 51 | { |
| 52 | //nolint:sliceofpointers |
| 53 | []*string{Ptr("a"), Ptr("b")}, |
| 54 | `["a" "b"]`, |
| 55 | }, |
| 56 | |
| 57 | // actual GitHub structs |
| 58 | { |
| 59 | Timestamp{time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)}, |
| 60 | `github.Timestamp{2006-01-02 15:04:05 +0000 UTC}`, |
| 61 | }, |
| 62 | { |
| 63 | &Timestamp{time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)}, |
| 64 | `github.Timestamp{2006-01-02 15:04:05 +0000 UTC}`, |
| 65 | }, |
| 66 | { |
| 67 | User{ID: Ptr(int64(123)), Name: Ptr("n")}, |
| 68 | `github.User{ID:123, Name:"n"}`, |
| 69 | }, |
| 70 | { |
| 71 | Repository{Owner: &User{ID: Ptr(int64(123))}}, |