Skip to content

Commit

Permalink
try fix wrong detect on cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
alingse committed Apr 20, 2023
1 parent 3cd153a commit e2a49b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.13.x
go-version: 1.17
- uses: actions/checkout@v3
- name: Build
run: go build .
Expand Down
27 changes: 27 additions & 0 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,30 @@ func TestCycle(t *testing.T) {
*iv = *i
t.Logf("Example long interface cycle:\n%# v", Formatter(i))
}

type AValue struct {
ID int
Name string
}

type ComplexValue struct {
AValues []*AValue
Values []interface{}
ByName map[string]interface{}
}

func TestReuseVisitMap(t *testing.T) {
var a = &AValue{ID: 1, Name: "A"}
var c = ComplexValue{
AValues: []*AValue{a},
Values: []interface{}{a},
ByName: map[string]interface{}{
"A": a,
},
}

var s = Sprint(c)
if strings.Contains(s, "CYCLIC") {
t.Error("there should not cycle in ComplexValue ", s)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kr/pretty

go 1.12
go 1.17

require (
github.com/kr/text v0.2.0
Expand Down

0 comments on commit e2a49b7

Please sign in to comment.