Skip to content

Commit fe0d655

Browse files
committed
Add tests for indirect circular references in maps and slices
1 parent 237fc7f commit fe0d655

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

print_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ func TestCircularData(t *testing.T) {
164164
circSlice := make([]any, 1)
165165
circSlice[0] = circSlice
166166

167+
// Test for indirect circular reference bug with maps
168+
// Map A -> Slice B -> Map A (should detect circular reference)
169+
circMap := make(map[string]any)
170+
indirectSlice := make([]any, 1)
171+
circMap["slice"] = indirectSlice
172+
indirectSlice[0] = circMap
173+
174+
// Test for indirect circular reference bug with nested maps
175+
// Map A -> Map B -> Map A (should detect circular reference)
176+
mapA := make(map[string]any)
177+
mapB := make(map[string]any)
178+
mapA["b"] = mapB
179+
mapB["a"] = mapA
180+
167181
tests := []struct {
168182
name string
169183
value any
@@ -184,6 +198,16 @@ func TestCircularData(t *testing.T) {
184198
value: circSlice,
185199
want: `[CIRCULAR_REF]`,
186200
},
201+
{
202+
name: "circMapViaSlice",
203+
value: circMap,
204+
want: `{` + "`slice`" + `:[CIRCULAR_REF]}`,
205+
},
206+
{
207+
name: "circMapViaMap",
208+
value: mapA,
209+
want: `{` + "`b`" + `:{` + "`a`" + `:CIRCULAR_REF}}`,
210+
},
187211
}
188212
for _, tt := range tests {
189213
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)