Skip to content

Commit

Permalink
Fixed rendering of named types that was accidentally removed in [0.5.2].
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Apr 7, 2024
1 parent 46fc3a7 commit 83fb77d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ The format is based on [Keep a Changelog], and this project adheres to
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [0.5.3] - 2024-04-08

### Fixed

- Fixed rendering of named types that was accidentally removed in [0.5.2].

## [0.5.2] - 2024-04-08

### Changed
Expand Down Expand Up @@ -211,6 +217,7 @@ preparation for unification of built-in and custom rendering behavior.
[0.5.0]: https://github.com/dogmatiq/dapper/releases/tag/v0.5.0
[0.5.1]: https://github.com/dogmatiq/dapper/releases/tag/v0.5.1
[0.5.2]: https://github.com/dogmatiq/dapper/releases/tag/v0.5.2
[0.5.3]: https://github.com/dogmatiq/dapper/releases/tag/v0.5.3
[#6]: https://github.com/dogmatiq/dapper/issues/6
[#7]: https://github.com/dogmatiq/dapper/issues/7
[#8]: https://github.com/dogmatiq/dapper/issues/8
Expand Down
2 changes: 2 additions & 0 deletions kind_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package dapper_test
import "testing"

func TestPrinter_Array(t *testing.T) {
type named [3]int
type local struct{}

test(t, "zero-value array", [3]int{}, "[3]int{<zero>}")
test(t, "named array", named{}, "github.com/dogmatiq/dapper_test.named{<zero>}")
test(t, "package path", [3]local{}, "[3]github.com/dogmatiq/dapper_test.local{<zero>}")

test(
Expand Down
2 changes: 2 additions & 0 deletions kind_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ type maps struct {
}

func TestPrinter_Map(t *testing.T) {
type named map[int]int
type local struct{}

test(t, "nil map", (map[int]int)(nil), "map[int]int(nil)")
test(t, "empty map", map[int]int{}, "map[int]int{}")
test(t, "named map", named{}, "github.com/dogmatiq/dapper_test.named{}")
test(t, "package path", map[local]local{}, "map[github.com/dogmatiq/dapper_test.local]github.com/dogmatiq/dapper_test.local{}")

test(
Expand Down
2 changes: 2 additions & 0 deletions kind_ptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package dapper_test
import "testing"

func TestPrinter_Ptr(t *testing.T) {
type named *int
type ptr struct {
Value any
}

value := 100
test(t, "nil pointer", (*int)(nil), "*int(nil)")
test(t, "non-nil pointer", &value, "*int(100)")
test(t, "named pointer", named(nil), "github.com/dogmatiq/dapper_test.named(nil)")
test(t, "package path", &ptr{}, "*github.com/dogmatiq/dapper_test.ptr{<zero>}")

test(
Expand Down
4 changes: 4 additions & 0 deletions kind_shallow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ func TestPrinter_UntypedPointer(t *testing.T) {

// This test provides additional tests for channel rendering.
func TestPrinter_Channel(t *testing.T) {
type named chan int
type local struct{}

test(t, "nil channel", (chan string)(nil), "(chan string)(nil)")
test(t, "recv-only channel", (<-chan string)(nil), "(<-chan string)(nil)")
test(t, "send-only channel", (chan<- string)(nil), "(chan<- string)(nil)")
test(t, "named channel", named(nil), "github.com/dogmatiq/dapper_test.named(nil)")
test(t, "package path", (chan local)(nil), "(chan github.com/dogmatiq/dapper_test.local)(nil)")

// a buffered channel will show it's "usage" ratio
Expand All @@ -215,6 +217,7 @@ func TestPrinter_Channel(t *testing.T) {

// This test provides additional tests for function rendering.
func TestPrinter_Func(t *testing.T) {
type named func(int) bool
type local struct{}

test(t, "no inputs or outputs", (func())(nil), "(func())(nil)")
Expand All @@ -224,6 +227,7 @@ func TestPrinter_Func(t *testing.T) {
test(t, "variadic with multiple inputs", (func(string, ...int))(nil), "(func(string, ...int))(nil)")
test(t, "single return value", (func() int)(nil), "(func() int)(nil)")
test(t, "multiple return values", (func() (int, bool))(nil), "(func() (int, bool))(nil)")
test(t, "named function", named(nil), "github.com/dogmatiq/dapper_test.named(nil)")
test(t, "package path", (func(local))(nil), "(func(github.com/dogmatiq/dapper_test.local))(nil)")
test(t, "everything", (func(local, ...int) (int, bool))(nil), "(func(github.com/dogmatiq/dapper_test.local, ...int) (int, bool))(nil)")
}
Expand Down
2 changes: 2 additions & 0 deletions kind_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import "testing"
// This test verifies that that slice value types are not rendered when they can
// be inferred from the context.
func TestPrinter_Slice(t *testing.T) {
type named []int
type local struct{}

test(t, "empty slice", []int{}, "[]int{}")
test(t, "named slice", named{}, "github.com/dogmatiq/dapper_test.named{}")
test(t, "package path", []local{}, "[]github.com/dogmatiq/dapper_test.local{}")

test(
Expand Down
5 changes: 5 additions & 0 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func (r *renderer) FormatType(v Value) string {
func (r *renderer) WriteType(v Value) {
t := v.DynamicType

if t.Name() != "" {
renderType(r, r.Configuration, t)
return
}

switch t.Kind() {
case reflect.Chan:
renderChanType(r, r.Configuration, t)
Expand Down

0 comments on commit 83fb77d

Please sign in to comment.