OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package reflect_test | 5 package reflect_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/base64" | 9 "encoding/base64" |
10 "fmt" | 10 "fmt" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 testType(t, 14, typ, "[]uint32") | 427 testType(t, 14, typ, "[]uint32") |
428 } | 428 } |
429 | 429 |
430 func TestInterfaceGet(t *testing.T) { | 430 func TestInterfaceGet(t *testing.T) { |
431 var inter struct { | 431 var inter struct { |
432 E interface{} | 432 E interface{} |
433 } | 433 } |
434 inter.E = 123.456 | 434 inter.E = 123.456 |
435 v1 := ValueOf(&inter) | 435 v1 := ValueOf(&inter) |
436 v2 := v1.Elem().Field(0) | 436 v2 := v1.Elem().Field(0) |
437 » assert(t, v2.Type().String(), "interface { }") | 437 » assert(t, v2.Type().String(), "interface {}") |
438 i2 := v2.Interface() | 438 i2 := v2.Interface() |
439 v3 := ValueOf(i2) | 439 v3 := ValueOf(i2) |
440 assert(t, v3.Type().String(), "float64") | 440 assert(t, v3.Type().String(), "float64") |
441 } | 441 } |
442 | 442 |
443 func TestInterfaceValue(t *testing.T) { | 443 func TestInterfaceValue(t *testing.T) { |
444 var inter struct { | 444 var inter struct { |
445 E interface{} | 445 E interface{} |
446 } | 446 } |
447 inter.E = 123.456 | 447 inter.E = 123.456 |
448 v1 := ValueOf(&inter) | 448 v1 := ValueOf(&inter) |
449 v2 := v1.Elem().Field(0) | 449 v2 := v1.Elem().Field(0) |
450 » assert(t, v2.Type().String(), "interface { }") | 450 » assert(t, v2.Type().String(), "interface {}") |
451 v3 := v2.Elem() | 451 v3 := v2.Elem() |
452 assert(t, v3.Type().String(), "float64") | 452 assert(t, v3.Type().String(), "float64") |
453 | 453 |
454 i3 := v2.Interface() | 454 i3 := v2.Interface() |
455 if _, ok := i3.(float64); !ok { | 455 if _, ok := i3.(float64); !ok { |
456 t.Error("v2.Interface() did not return float64, got ", TypeOf(i3
)) | 456 t.Error("v2.Interface() did not return float64, got ", TypeOf(i3
)) |
457 } | 457 } |
458 } | 458 } |
459 | 459 |
460 func TestFunctionValue(t *testing.T) { | 460 func TestFunctionValue(t *testing.T) { |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 if x == nil { | 1646 if x == nil { |
1647 panic("nil interface") | 1647 panic("nil interface") |
1648 } | 1648 } |
1649 } | 1649 } |
1650 | 1650 |
1651 func isValid(v Value) { | 1651 func isValid(v Value) { |
1652 if !v.IsValid() { | 1652 if !v.IsValid() { |
1653 panic("zero Value") | 1653 panic("zero Value") |
1654 } | 1654 } |
1655 } | 1655 } |
OLD | NEW |