Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into string_indent
Browse files Browse the repository at this point in the history
  • Loading branch information
david-littlefarmer committed Dec 19, 2023
2 parents 41c7016 + 0bb4d22 commit e593f99
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions devslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ func (h *developHandler) elementType(t reflect.Type, v reflect.Value, l int, p i

// b = atb(s)
}
case reflect.Interface:
v = reflect.ValueOf(v.Interface())
b = h.elementType(v.Type(), v, l)

Check failure on line 563 in devslog.go

View workflow job for this annotation

GitHub Actions / Test check

not enough arguments in call to h.elementType
default:
b = atb("Unknown type: ")
b = append(b, atb(v.Kind())...)
Expand Down
21 changes: 21 additions & 0 deletions devslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func Test_Types(t *testing.T) {
test_SliceBig(t, opts)
test_Map(t, opts)
test_MapOfPointers(t, opts)
test_MapOfInterface(t, opts)
test_Struct(t, opts)
test_Group(t, opts)
test_LogValuer(t, opts)
Expand Down Expand Up @@ -653,6 +654,26 @@ func test_MapOfPointers(t *testing.T, o *Options) {
}
}

func test_MapOfInterface(t *testing.T, o *Options) {
w := &MockWriter{}
logger := slog.New(NewHandler(w, o))

m := map[int]any{0: "a", 1: "b"}
mp := &m

logger.Info("msg",
slog.Any("m", m),
slog.Any("mp", mp),
slog.Any("mpp", &mp),
)

expected := []byte("\x1b[2m\x1b[37m[]\x1b[0m \x1b[42m\x1b[30m INFO \x1b[0m \x1b[32mmsg\x1b[0m\n\x1b[32mM\x1b[0m \x1b[35mm\x1b[0m : \x1b[34m2\x1b[0m \x1b[33mm\x1b[0m\x1b[33ma\x1b[0m\x1b[33mp\x1b[0m\x1b[32m[\x1b[0m\x1b[33mi\x1b[0m\x1b[33mn\x1b[0m\x1b[33mt\x1b[0m\x1b[32m]\x1b[0m\x1b[33mi\x1b[0m\x1b[33mn\x1b[0m\x1b[33mt\x1b[0m\x1b[33me\x1b[0m\x1b[33mr\x1b[0m\x1b[33mf\x1b[0m\x1b[33ma\x1b[0m\x1b[33mc\x1b[0m\x1b[33me\x1b[0m\x1b[33m \x1b[0m\x1b[33m{\x1b[0m\x1b[33m}\x1b[0m\n \x1b[32m0\x1b[0m: a\n \x1b[32m1\x1b[0m: b\n\x1b[32mM\x1b[0m \x1b[35mmp\x1b[0m : \x1b[34m2\x1b[0m \x1b[31m*\x1b[0m\x1b[33mm\x1b[0m\x1b[33ma\x1b[0m\x1b[33mp\x1b[0m\x1b[32m[\x1b[0m\x1b[33mi\x1b[0m\x1b[33mn\x1b[0m\x1b[33mt\x1b[0m\x1b[32m]\x1b[0m\x1b[33mi\x1b[0m\x1b[33mn\x1b[0m\x1b[33mt\x1b[0m\x1b[33me\x1b[0m\x1b[33mr\x1b[0m\x1b[33mf\x1b[0m\x1b[33ma\x1b[0m\x1b[33mc\x1b[0m\x1b[33me\x1b[0m\x1b[33m \x1b[0m\x1b[33m{\x1b[0m\x1b[33m}\x1b[0m\n \x1b[32m0\x1b[0m: a\n \x1b[32m1\x1b[0m: b\n\x1b[32mM\x1b[0m \x1b[35mmpp\x1b[0m: \x1b[34m2\x1b[0m \x1b[31m*\x1b[0m\x1b[31m*\x1b[0m\x1b[33mm\x1b[0m\x1b[33ma\x1b[0m\x1b[33mp\x1b[0m\x1b[32m[\x1b[0m\x1b[33mi\x1b[0m\x1b[33mn\x1b[0m\x1b[33mt\x1b[0m\x1b[32m]\x1b[0m\x1b[33mi\x1b[0m\x1b[33mn\x1b[0m\x1b[33mt\x1b[0m\x1b[33me\x1b[0m\x1b[33mr\x1b[0m\x1b[33mf\x1b[0m\x1b[33ma\x1b[0m\x1b[33mc\x1b[0m\x1b[33me\x1b[0m\x1b[33m \x1b[0m\x1b[33m{\x1b[0m\x1b[33m}\x1b[0m\n \x1b[32m0\x1b[0m: a\n \x1b[32m1\x1b[0m: b\n\n")

if !bytes.Equal(w.WrittenData, expected) {
t.Errorf("\nExpected:\n%s\nGot:\n%s\nExpected:\n%[1]q\nGot:\n%[2]q", expected, w.WrittenData)
}
}

func test_Struct(t *testing.T, o *Options) {
w := &MockWriter{}
logger := slog.New(NewHandler(w, o))
Expand Down

0 comments on commit e593f99

Please sign in to comment.