libf hai 1 ano
pai
achega
0fe827c278
Modificáronse 1 ficheiros con 40 adicións e 0 borrados
  1. 40 0
      nil/nil_test.go

+ 40 - 0
nil/nil_test.go

@@ -0,0 +1,40 @@
+package nil_test
+
+import (
+	"fmt"
+	"testing"
+)
+
+type Interface interface {
+	String() string
+}
+
+type Struct struct {
+	sval string
+}
+
+func (me *Struct) String() string {
+	if me == nil {
+		return "nil"
+	}
+	return me.sval
+}
+
+func TestAll(t *testing.T) {
+
+	var n Interface
+
+	var x *Struct
+
+	func() {
+		defer func() {
+			x := recover()
+			if x != nil {
+				println(fmt.Sprint(x))
+			}
+		}()
+		x = n.(*Struct)
+	}()
+
+	fmt.Println(x.String())
+}