OSDN Git Service

libgo: Update to weekly.2011-11-18.
[pf3gnuchains/gcc-fork.git] / libgo / go / reflect / all_test.go
index 98b6e23..cf31d1b 100644 (file)
@@ -16,6 +16,13 @@ import (
        "unsafe"
 )
 
+func TestBool(t *testing.T) {
+       v := ValueOf(true)
+       if v.Bool() != true {
+               t.Fatal("ValueOf(true).Bool() = false")
+       }
+}
+
 type integer int
 type T struct {
        a int
@@ -215,7 +222,8 @@ func TestTypes(t *testing.T) {
 
 func TestSet(t *testing.T) {
        for i, tt := range valueTests {
-               v := ValueOf(tt.i).Elem()
+               v := ValueOf(tt.i)
+               v = v.Elem()
                switch v.Kind() {
                case Int:
                        v.SetInt(132)
@@ -631,7 +639,7 @@ var deepEqualTests = []DeepEqualTest{
        {make([]int, 10), make([]int, 10), true},
        {&[3]int{1, 2, 3}, &[3]int{1, 2, 3}, true},
        {Basic{1, 0.5}, Basic{1, 0.5}, true},
-       {os.Error(nil), os.Error(nil), true},
+       {error(nil), error(nil), true},
        {map[int]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, true},
 
        // Inequalities
@@ -651,6 +659,14 @@ var deepEqualTests = []DeepEqualTest{
        {nil, 1, false},
        {1, nil, false},
 
+       // Nil vs empty: not the same.
+       {[]int{}, []int(nil), false},
+       {[]int{}, []int{}, true},
+       {[]int(nil), []int(nil), true},
+       {map[int]int{}, map[int]int(nil), false},
+       {map[int]int{}, map[int]int{}, true},
+       {map[int]int(nil), map[int]int(nil), true},
+
        // Mismatched types
        {1, 1.0, false},
        {int32(1), int64(1), false},
@@ -1092,21 +1108,38 @@ func TestMethod(t *testing.T) {
        }
 
        // Curried method of value.
-       i = ValueOf(p).Method(1).Call([]Value{ValueOf(10)})[0].Int()
+       tfunc := TypeOf(func(int) int(nil))
+       v := ValueOf(p).Method(1)
+       if tt := v.Type(); tt != tfunc {
+               t.Errorf("Value Method Type is %s; want %s", tt, tfunc)
+       }
+       i = v.Call([]Value{ValueOf(10)})[0].Int()
        if i != 250 {
                t.Errorf("Value Method returned %d; want 250", i)
        }
-       i = ValueOf(p).MethodByName("Dist").Call([]Value{ValueOf(10)})[0].Int()
+       v = ValueOf(p).MethodByName("Dist")
+       if tt := v.Type(); tt != tfunc {
+               t.Errorf("Value MethodByName Type is %s; want %s", tt, tfunc)
+       }
+       i = v.Call([]Value{ValueOf(10)})[0].Int()
        if i != 250 {
                t.Errorf("Value MethodByName returned %d; want 250", i)
        }
 
        // Curried method of pointer.
-       i = ValueOf(&p).Method(1).Call([]Value{ValueOf(10)})[0].Int()
+       v = ValueOf(&p).Method(1)
+       if tt := v.Type(); tt != tfunc {
+               t.Errorf("Pointer Value Method Type is %s; want %s", tt, tfunc)
+       }
+       i = v.Call([]Value{ValueOf(10)})[0].Int()
        if i != 250 {
                t.Errorf("Pointer Value Method returned %d; want 250", i)
        }
-       i = ValueOf(&p).MethodByName("Dist").Call([]Value{ValueOf(10)})[0].Int()
+       v = ValueOf(&p).MethodByName("Dist")
+       if tt := v.Type(); tt != tfunc {
+               t.Errorf("Pointer Value MethodByName Type is %s; want %s", tt, tfunc)
+       }
+       i = v.Call([]Value{ValueOf(10)})[0].Int()
        if i != 250 {
                t.Errorf("Pointer Value MethodByName returned %d; want 250", i)
        }
@@ -1121,11 +1154,19 @@ func TestMethod(t *testing.T) {
                }
        }{p}
        pv := ValueOf(s).Field(0)
-       i = pv.Method(0).Call([]Value{ValueOf(10)})[0].Int()
+       v = pv.Method(0)
+       if tt := v.Type(); tt != tfunc {
+               t.Errorf("Interface Method Type is %s; want %s", tt, tfunc)
+       }
+       i = v.Call([]Value{ValueOf(10)})[0].Int()
        if i != 250 {
                t.Errorf("Interface Method returned %d; want 250", i)
        }
-       i = pv.MethodByName("Dist").Call([]Value{ValueOf(10)})[0].Int()
+       v = pv.MethodByName("Dist")
+       if tt := v.Type(); tt != tfunc {
+               t.Errorf("Interface MethodByName Type is %s; want %s", tt, tfunc)
+       }
+       i = v.Call([]Value{ValueOf(10)})[0].Int()
        if i != 250 {
                t.Errorf("Interface MethodByName returned %d; want 250", i)
        }