(t *testing.T)
| 19 | var _, mapTestFile, _, _ = runtime.Caller(0) |
| 20 | |
| 21 | func TestMap(t *testing.T) { |
| 22 | t.Parallel() |
| 23 | |
| 24 | test := func(t *testing.T, m slog.Map, exp string) { |
| 25 | t.Helper() |
| 26 | exp = indentJSON(t, exp) |
| 27 | act := marshalJSON(t, m) |
| 28 | assert.Equal(t, "JSON", exp, act) |
| 29 | } |
| 30 | |
| 31 | t.Run("JSON", func(t *testing.T) { |
| 32 | t.Parallel() |
| 33 | |
| 34 | type Meow struct { |
| 35 | Wow string `json:"meow"` |
| 36 | Something int `json:",omitempty"` |
| 37 | Ignored bool `json:"-"` |
| 38 | } |
| 39 | |
| 40 | test(t, slog.M( |
| 41 | slog.Error( |
| 42 | xerrors.Errorf("wrap1: %w", |
| 43 | xerrors.Errorf("wrap2: %w", |
| 44 | io.EOF, |
| 45 | ), |
| 46 | ), |
| 47 | ), |
| 48 | slog.F("meow", struct { |
| 49 | Izi string `json:"izi"` |
| 50 | M *Meow `json:"Amazing"` |
| 51 | |
| 52 | ignored bool |
| 53 | }{ |
| 54 | Izi: "sogood", |
| 55 | M: &Meow{ |
| 56 | Wow: "", |
| 57 | Something: 0, |
| 58 | Ignored: true, |
| 59 | }, |
| 60 | }), |
| 61 | ), `{ |
| 62 | "error": [ |
| 63 | { |
| 64 | "msg": "wrap1", |
| 65 | "fun": "cdr.dev/slog/v3_test.TestMap.func2", |
| 66 | "loc": "`+mapTestFile+`:42" |
| 67 | }, |
| 68 | { |
| 69 | "msg": "wrap2", |
| 70 | "fun": "cdr.dev/slog/v3_test.TestMap.func2", |
| 71 | "loc": "`+mapTestFile+`:43" |
| 72 | }, |
| 73 | "EOF" |
| 74 | ], |
| 75 | "meow": { |
| 76 | "izi": "sogood", |
| 77 | "Amazing": { |
| 78 | "meow": "" |
nothing calls this directly
no test coverage detected