diff --git a/_cmptest/reflect_indirect/test.go b/_cmptest/reflect_indirect/test.go deleted file mode 100644 index 29fcf750..00000000 --- a/_cmptest/reflect_indirect/test.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - "reflect" -) - -func main() { - x := 42 - p := &x - - // Test 1: Non-pointer value - should return same value - v1 := reflect.Indirect(reflect.ValueOf(x)) - fmt.Printf("Non-pointer: %v\n", v1.Interface()) - - // Test 2: Pointer - should dereference - v2 := reflect.Indirect(reflect.ValueOf(p)) - fmt.Printf("Pointer: %v\n", v2.Interface()) - - // Test 3: Nil pointer - var nilPtr *int - v3 := reflect.Indirect(reflect.ValueOf(nilPtr)) - fmt.Printf("Nil pointer valid: %v\n", v3.IsValid()) -} diff --git a/_demo/go/reflect-indirect/reflect-indirect.go b/_demo/go/reflect-indirect/reflect-indirect.go new file mode 100644 index 00000000..4deb79e8 --- /dev/null +++ b/_demo/go/reflect-indirect/reflect-indirect.go @@ -0,0 +1,31 @@ +package main + +import ( + "reflect" +) + +func main() { + x := 42 + p := &x + + // Test 1: Non-pointer value - should return same value + v1 := reflect.Indirect(reflect.ValueOf(x)) + if !v1.IsValid() || v1.Interface() != 42 { + panic("Non-pointer test failed: expected 42") + } + + // Test 2: Pointer - should dereference + v2 := reflect.Indirect(reflect.ValueOf(p)) + if !v2.IsValid() || v2.Interface() != 42 { + panic("Pointer dereference test failed: expected 42") + } + + // Test 3: Nil pointer - should return invalid Value + var nilPtr *int + v3 := reflect.Indirect(reflect.ValueOf(nilPtr)) + if v3.IsValid() { + panic("Nil pointer test failed: expected invalid Value") + } + + println("PASS") +}