From a74ca940e2859cc43c53bc459db25dd36c6118c0 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Mon, 20 Oct 2025 02:29:18 +0000 Subject: [PATCH] feat(reflect): add struct test cases for Indirect function Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang --- _demo/go/reflectindirect/reflect-indirect.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/_demo/go/reflectindirect/reflect-indirect.go b/_demo/go/reflectindirect/reflect-indirect.go index 4deb79e8..69332a47 100644 --- a/_demo/go/reflectindirect/reflect-indirect.go +++ b/_demo/go/reflectindirect/reflect-indirect.go @@ -27,5 +27,23 @@ func main() { panic("Nil pointer test failed: expected invalid Value") } + // Test 4: Struct value - should return same value + type Person struct { + Name string + Age int + } + person := Person{Name: "Alice", Age: 30} + v4 := reflect.Indirect(reflect.ValueOf(person)) + if !v4.IsValid() || v4.Interface().(Person).Name != "Alice" || v4.Interface().(Person).Age != 30 { + panic("Struct value test failed: expected Person{Name: Alice, Age: 30}") + } + + // Test 5: Struct pointer - should dereference + personPtr := &Person{Name: "Bob", Age: 25} + v5 := reflect.Indirect(reflect.ValueOf(personPtr)) + if !v5.IsValid() || v5.Interface().(Person).Name != "Bob" || v5.Interface().(Person).Age != 25 { + panic("Struct pointer test failed: expected Person{Name: Bob, Age: 25}") + } + println("PASS") }