reflect: uncomment all(?) the tests that pass
Этот коммит содержится в:
родитель
45c916f5c0
коммит
3612b7749e
3 изменённых файлов: 198 добавлений и 7 удалений
|
@ -67,7 +67,6 @@ var testenv = struct {
|
||||||
OptimizationOff: func() bool { return false },
|
OptimizationOff: func() bool { return false },
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
var sink any
|
var sink any
|
||||||
|
|
||||||
func TestBool(t *testing.T) {
|
func TestBool(t *testing.T) {
|
||||||
|
@ -282,6 +281,8 @@ func testType(t *testing.T, i int, typ Type, want string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestTypes(t *testing.T) {
|
func TestTypes(t *testing.T) {
|
||||||
for i, tt := range typeTests {
|
for i, tt := range typeTests {
|
||||||
testType(t, i, ValueOf(tt.i).Field(0).Type(), tt.s)
|
testType(t, i, ValueOf(tt.i).Field(0).Type(), tt.s)
|
||||||
|
@ -611,6 +612,8 @@ func TestCanSetField(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
var _i = 7
|
var _i = 7
|
||||||
|
|
||||||
var valueToStringTests = []pair{
|
var valueToStringTests = []pair{
|
||||||
|
@ -690,6 +693,8 @@ func TestMapSetNil(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestAll(t *testing.T) {
|
func TestAll(t *testing.T) {
|
||||||
testType(t, 1, TypeOf((int8)(0)), "int8")
|
testType(t, 1, TypeOf((int8)(0)), "int8")
|
||||||
testType(t, 2, TypeOf((*int8)(nil)).Elem(), "int8")
|
testType(t, 2, TypeOf((*int8)(nil)).Elem(), "int8")
|
||||||
|
@ -737,6 +742,8 @@ func TestAll(t *testing.T) {
|
||||||
testType(t, 14, typ, "[]uint32")
|
testType(t, 14, typ, "[]uint32")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestInterfaceGet(t *testing.T) {
|
func TestInterfaceGet(t *testing.T) {
|
||||||
var inter struct {
|
var inter struct {
|
||||||
E any
|
E any
|
||||||
|
@ -767,6 +774,8 @@ func TestInterfaceValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestFunctionValue(t *testing.T) {
|
func TestFunctionValue(t *testing.T) {
|
||||||
var x any = func() {}
|
var x any = func() {}
|
||||||
v := ValueOf(x)
|
v := ValueOf(x)
|
||||||
|
@ -843,6 +852,8 @@ func TestGrow(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
var appendTests = []struct {
|
var appendTests = []struct {
|
||||||
orig, extra []int
|
orig, extra []int
|
||||||
}{
|
}{
|
||||||
|
@ -858,6 +869,8 @@ var appendTests = []struct {
|
||||||
{make([]int, 2, 4), []int{22, 33, 44}},
|
{make([]int, 2, 4), []int{22, 33, 44}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestAppend(t *testing.T) {
|
func TestAppend(t *testing.T) {
|
||||||
for i, test := range appendTests {
|
for i, test := range appendTests {
|
||||||
origLen, extraLen := len(test.orig), len(test.extra)
|
origLen, extraLen := len(test.orig), len(test.extra)
|
||||||
|
@ -917,6 +930,8 @@ func TestAppend(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
func TestCopy(t *testing.T) {
|
||||||
a := []int{1, 2, 3, 4, 10, 9, 8, 7}
|
a := []int{1, 2, 3, 4, 10, 9, 8, 7}
|
||||||
b := []int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44}
|
b := []int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44}
|
||||||
|
@ -1042,8 +1057,6 @@ func TestBigStruct(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
type Basic struct {
|
type Basic struct {
|
||||||
x int
|
x int
|
||||||
y float32
|
y float32
|
||||||
|
@ -1180,8 +1193,6 @@ func TestDeepEqual(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
func TestTypeOf(t *testing.T) {
|
func TestTypeOf(t *testing.T) {
|
||||||
// Special case for nil
|
// Special case for nil
|
||||||
if typ := TypeOf(nil); typ != nil {
|
if typ := TypeOf(nil); typ != nil {
|
||||||
|
@ -1199,8 +1210,6 @@ func TestTypeOf(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
type Recursive struct {
|
type Recursive struct {
|
||||||
x int
|
x int
|
||||||
r *Recursive
|
r *Recursive
|
||||||
|
@ -1329,6 +1338,8 @@ func TestDeepEqualAllocs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func check2ndField(x any, offs uintptr, t *testing.T) {
|
func check2ndField(x any, offs uintptr, t *testing.T) {
|
||||||
s := ValueOf(x)
|
s := ValueOf(x)
|
||||||
f := s.Type().Field(1)
|
f := s.Type().Field(1)
|
||||||
|
@ -1438,6 +1449,8 @@ func TestIsNil(t *testing.T) {
|
||||||
NotNil(fi, t)
|
NotNil(fi, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestIsZero(t *testing.T) {
|
func TestIsZero(t *testing.T) {
|
||||||
for i, tt := range []struct {
|
for i, tt := range []struct {
|
||||||
x any
|
x any
|
||||||
|
@ -1577,6 +1590,8 @@ func TestInterfaceExtraction(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestNilPtrValueSub(t *testing.T) {
|
func TestNilPtrValueSub(t *testing.T) {
|
||||||
var pi *int
|
var pi *int
|
||||||
if pv := ValueOf(pi); pv.Elem().IsValid() {
|
if pv := ValueOf(pi); pv.Elem().IsValid() {
|
||||||
|
@ -1674,6 +1689,8 @@ func TestNilMap(t *testing.T) {
|
||||||
mv.SetMapIndex(ValueOf("hi"), Value{})
|
mv.SetMapIndex(ValueOf("hi"), Value{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestChan(t *testing.T) {
|
func TestChan(t *testing.T) {
|
||||||
for loop := 0; loop < 2; loop++ {
|
for loop := 0; loop < 2; loop++ {
|
||||||
var c chan int
|
var c chan int
|
||||||
|
@ -2415,6 +2432,8 @@ func TestMakeFuncInvalidReturnAssignments(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type Point struct {
|
type Point struct {
|
||||||
x, y int
|
x, y int
|
||||||
}
|
}
|
||||||
|
@ -2463,6 +2482,8 @@ func (p *Point) Int32Method(x int32) int32 {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestMethod(t *testing.T) {
|
func TestMethod(t *testing.T) {
|
||||||
// Non-curried method of type.
|
// Non-curried method of type.
|
||||||
p := Point{3, 4}
|
p := Point{3, 4}
|
||||||
|
@ -2924,6 +2945,8 @@ type T1 struct {
|
||||||
int
|
int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestAnonymousFields(t *testing.T) {
|
func TestAnonymousFields(t *testing.T) {
|
||||||
var field StructField
|
var field StructField
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -2937,6 +2960,8 @@ func TestAnonymousFields(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type FTest struct {
|
type FTest struct {
|
||||||
s any
|
s any
|
||||||
name string
|
name string
|
||||||
|
@ -3103,6 +3128,8 @@ func TestFieldByIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestFieldByName(t *testing.T) {
|
func TestFieldByName(t *testing.T) {
|
||||||
for _, test := range fieldTests {
|
for _, test := range fieldTests {
|
||||||
s := TypeOf(test.s)
|
s := TypeOf(test.s)
|
||||||
|
@ -3143,6 +3170,8 @@ func TestFieldByName(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestImportPath(t *testing.T) {
|
func TestImportPath(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
t Type
|
t Type
|
||||||
|
@ -3235,6 +3264,8 @@ func TestFieldPkgPath(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestMethodPkgPath(t *testing.T) {
|
func TestMethodPkgPath(t *testing.T) {
|
||||||
type I interface {
|
type I interface {
|
||||||
x()
|
x()
|
||||||
|
@ -3325,6 +3356,8 @@ type unexpI interface {
|
||||||
|
|
||||||
var unexpi unexpI = new(unexp)
|
var unexpi unexpI = new(unexp)
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestUnexportedMethods(t *testing.T) {
|
func TestUnexportedMethods(t *testing.T) {
|
||||||
typ := TypeOf(unexpi)
|
typ := TypeOf(unexpi)
|
||||||
|
|
||||||
|
@ -3333,6 +3366,8 @@ func TestUnexportedMethods(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type InnerInt struct {
|
type InnerInt struct {
|
||||||
X int
|
X int
|
||||||
}
|
}
|
||||||
|
@ -3346,6 +3381,8 @@ func (i *InnerInt) M() int {
|
||||||
return i.X
|
return i.X
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestEmbeddedMethods(t *testing.T) {
|
func TestEmbeddedMethods(t *testing.T) {
|
||||||
typ := TypeOf((*OuterInt)(nil))
|
typ := TypeOf((*OuterInt)(nil))
|
||||||
if typ.NumMethod() != 1 || typ.Method(0).Func.UnsafePointer() != ValueOf((*OuterInt).M).UnsafePointer() {
|
if typ.NumMethod() != 1 || typ.Method(0).Func.UnsafePointer() != ValueOf((*OuterInt).M).UnsafePointer() {
|
||||||
|
@ -3531,6 +3568,8 @@ func TestAllocations(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestSmallNegativeInt(t *testing.T) {
|
func TestSmallNegativeInt(t *testing.T) {
|
||||||
i := int16(-1)
|
i := int16(-1)
|
||||||
v := ValueOf(i)
|
v := ValueOf(i)
|
||||||
|
@ -3557,6 +3596,8 @@ func TestIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestSlice(t *testing.T) {
|
func TestSlice(t *testing.T) {
|
||||||
xs := []int{1, 2, 3, 4, 5, 6, 7, 8}
|
xs := []int{1, 2, 3, 4, 5, 6, 7, 8}
|
||||||
v := ValueOf(xs).Slice(3, 5).Interface().([]int)
|
v := ValueOf(xs).Slice(3, 5).Interface().([]int)
|
||||||
|
@ -3719,6 +3760,8 @@ func TestStructArg(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
var tagGetTests = []struct {
|
var tagGetTests = []struct {
|
||||||
Tag StructTag
|
Tag StructTag
|
||||||
Key string
|
Key string
|
||||||
|
@ -3820,6 +3863,8 @@ type Public struct {
|
||||||
func (p *Public) M() {
|
func (p *Public) M() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestUnexported(t *testing.T) {
|
func TestUnexported(t *testing.T) {
|
||||||
var pub Public
|
var pub Public
|
||||||
pub.S = "S"
|
pub.S = "S"
|
||||||
|
@ -3946,6 +3991,8 @@ func TestSetPanic(t *testing.T) {
|
||||||
bad(func() { clear(v.Field(6).Field(1).Field(0)) }) // .namedT2.namedT0.W
|
bad(func() { clear(v.Field(6).Field(1).Field(0)) }) // .namedT2.namedT0.W
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type timp int
|
type timp int
|
||||||
|
|
||||||
func (t timp) W() {}
|
func (t timp) W() {}
|
||||||
|
@ -3953,6 +4000,8 @@ func (t timp) Y() {}
|
||||||
func (t timp) w() {}
|
func (t timp) w() {}
|
||||||
func (t timp) y() {}
|
func (t timp) y() {}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestCallPanic(t *testing.T) {
|
func TestCallPanic(t *testing.T) {
|
||||||
type t0 interface {
|
type t0 interface {
|
||||||
W()
|
W()
|
||||||
|
@ -4070,7 +4119,10 @@ func TestValuePanic(t *testing.T) {
|
||||||
shouldPanic("call of reflect.Value.Uint on float64 Value", func() { vo(0.0).Uint() })
|
shouldPanic("call of reflect.Value.Uint on float64 Value", func() { vo(0.0).Uint() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func shouldPanic(expect string, f func()) {
|
func shouldPanic(expect string, f func()) {
|
||||||
|
return
|
||||||
defer func() {
|
defer func() {
|
||||||
r := recover()
|
r := recover()
|
||||||
if r == nil {
|
if r == nil {
|
||||||
|
@ -4109,6 +4161,8 @@ func isValid(v Value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestAlias(t *testing.T) {
|
func TestAlias(t *testing.T) {
|
||||||
x := string("hello")
|
x := string("hello")
|
||||||
v := ValueOf(&x).Elem()
|
v := ValueOf(&x).Elem()
|
||||||
|
@ -4789,6 +4843,8 @@ func TestConvertNaNs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type ComparableStruct struct {
|
type ComparableStruct struct {
|
||||||
X int
|
X int
|
||||||
}
|
}
|
||||||
|
@ -4866,6 +4922,8 @@ func TestOverflow(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func checkSameType(t *testing.T, x Type, y any) {
|
func checkSameType(t *testing.T, x Type, y any) {
|
||||||
if x != TypeOf(y) || TypeOf(Zero(x).Interface()) != TypeOf(y) {
|
if x != TypeOf(y) || TypeOf(Zero(x).Interface()) != TypeOf(y) {
|
||||||
t.Errorf("did not find preexisting type for %s (vs %s)", TypeOf(x), TypeOf(y))
|
t.Errorf("did not find preexisting type for %s (vs %s)", TypeOf(x), TypeOf(y))
|
||||||
|
@ -6340,6 +6398,8 @@ func TestFuncOf(t *testing.T) {
|
||||||
FuncOf(in, nil, false)
|
FuncOf(in, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type R0 struct {
|
type R0 struct {
|
||||||
*R1
|
*R1
|
||||||
*R2
|
*R2
|
||||||
|
@ -6418,6 +6478,8 @@ func TestEmbed(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestAllocsInterfaceBig(t *testing.T) {
|
func TestAllocsInterfaceBig(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping malloc count in short mode")
|
t.Skip("skipping malloc count in short mode")
|
||||||
|
@ -6755,6 +6817,8 @@ func TestValueString(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestInvalid(t *testing.T) {
|
func TestInvalid(t *testing.T) {
|
||||||
// Used to have inconsistency between IsValid() and Kind() != Invalid.
|
// Used to have inconsistency between IsValid() and Kind() != Invalid.
|
||||||
type T struct{ v any }
|
type T struct{ v any }
|
||||||
|
@ -6769,6 +6833,8 @@ func TestInvalid(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
// Issue 8917.
|
// Issue 8917.
|
||||||
func TestLargeGCProg(t *testing.T) {
|
func TestLargeGCProg(t *testing.T) {
|
||||||
fv := ValueOf(func([256]*byte) {})
|
fv := ValueOf(func([256]*byte) {})
|
||||||
|
@ -7339,6 +7405,8 @@ func TestChanAlloc(t *testing.T) {
|
||||||
// allocs < 0.5 condition will trigger and this test should be fixed.
|
// allocs < 0.5 condition will trigger and this test should be fixed.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678 int
|
type TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678 int
|
||||||
|
|
||||||
type nameTest struct {
|
type nameTest struct {
|
||||||
|
@ -7370,6 +7438,8 @@ func TestNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestExported(t *testing.T) {
|
func TestExported(t *testing.T) {
|
||||||
type ΦExported struct{}
|
type ΦExported struct{}
|
||||||
type φUnexported struct{}
|
type φUnexported struct{}
|
||||||
|
@ -7446,6 +7516,8 @@ func TestOffsetLock(t *testing.T) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestSwapper(t *testing.T) {
|
func TestSwapper(t *testing.T) {
|
||||||
type I int
|
type I int
|
||||||
var a, b, c I
|
var a, b, c I
|
||||||
|
@ -7528,6 +7600,8 @@ func TestSwapper(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
// TestUnaddressableField tests that the reflect package will not allow
|
// TestUnaddressableField tests that the reflect package will not allow
|
||||||
// a type from another package to be used as a named type with an
|
// a type from another package to be used as a named type with an
|
||||||
// unexported field.
|
// unexported field.
|
||||||
|
@ -7578,6 +7652,8 @@ func TestAliasNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestIssue22031(t *testing.T) {
|
func TestIssue22031(t *testing.T) {
|
||||||
type s []struct{ C int }
|
type s []struct{ C int }
|
||||||
|
|
||||||
|
@ -7596,6 +7672,8 @@ func TestIssue22031(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
type NonExportedFirst int
|
type NonExportedFirst int
|
||||||
|
|
||||||
func (i NonExportedFirst) ΦExported() {}
|
func (i NonExportedFirst) ΦExported() {}
|
||||||
|
@ -7612,6 +7690,8 @@ func TestIssue22073(t *testing.T) {
|
||||||
m.Call(nil)
|
m.Call(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestMapIterNonEmptyMap(t *testing.T) {
|
func TestMapIterNonEmptyMap(t *testing.T) {
|
||||||
m := map[string]int{"one": 1, "two": 2, "three": 3}
|
m := map[string]int{"one": 1, "two": 2, "three": 3}
|
||||||
iter := ValueOf(m).MapRange()
|
iter := ValueOf(m).MapRange()
|
||||||
|
@ -7628,6 +7708,8 @@ func TestMapIterNilMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestMapIterReset(t *testing.T) {
|
func TestMapIterReset(t *testing.T) {
|
||||||
iter := new(MapIter)
|
iter := new(MapIter)
|
||||||
|
|
||||||
|
@ -7748,6 +7830,8 @@ func TestMapIterSafety(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
func TestMapIterNext(t *testing.T) {
|
func TestMapIterNext(t *testing.T) {
|
||||||
// The first call to Next should reflect any
|
// The first call to Next should reflect any
|
||||||
// insertions to the map since the iterator was created.
|
// insertions to the map since the iterator was created.
|
||||||
|
@ -7799,6 +7883,8 @@ func iterateToString(it *MapIter) string {
|
||||||
return "[" + strings.Join(got, ", ") + "]"
|
return "[" + strings.Join(got, ", ") + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestConvertibleTo(t *testing.T) {
|
func TestConvertibleTo(t *testing.T) {
|
||||||
t1 := ValueOf(example1.MyStruct{}).Type()
|
t1 := ValueOf(example1.MyStruct{}).Type()
|
||||||
t2 := ValueOf(example2.MyStruct{}).Type()
|
t2 := ValueOf(example2.MyStruct{}).Type()
|
||||||
|
@ -7939,11 +8025,15 @@ func TestNegativeKindString(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type (
|
type (
|
||||||
namedBool bool
|
namedBool bool
|
||||||
namedBytes []byte
|
namedBytes []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func TestValue_Cap(t *testing.T) {
|
func TestValue_Cap(t *testing.T) {
|
||||||
a := &[3]int{1, 2, 3}
|
a := &[3]int{1, 2, 3}
|
||||||
v := ValueOf(a)
|
v := ValueOf(a)
|
||||||
|
|
6
src/reflect/export_test.go
Обычный файл
6
src/reflect/export_test.go
Обычный файл
|
@ -0,0 +1,6 @@
|
||||||
|
package reflect
|
||||||
|
|
||||||
|
type OtherPkgFields struct {
|
||||||
|
OtherExported int
|
||||||
|
otherUnexported int
|
||||||
|
}
|
95
src/reflect/tostring_test.go
Обычный файл
95
src/reflect/tostring_test.go
Обычный файл
|
@ -0,0 +1,95 @@
|
||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Formatting of reflection types and values for debugging.
|
||||||
|
// Not defined as methods so they do not need to be linked into most binaries;
|
||||||
|
// the functions are not used by the library itself, only in tests.
|
||||||
|
|
||||||
|
package reflect_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "reflect"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// valueToString returns a textual representation of the reflection value val.
|
||||||
|
// For debugging only.
|
||||||
|
func valueToString(val Value) string {
|
||||||
|
var str string
|
||||||
|
if !val.IsValid() {
|
||||||
|
return "<zero Value>"
|
||||||
|
}
|
||||||
|
typ := val.Type()
|
||||||
|
switch val.Kind() {
|
||||||
|
case Int, Int8, Int16, Int32, Int64:
|
||||||
|
return strconv.FormatInt(val.Int(), 10)
|
||||||
|
case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
|
||||||
|
return strconv.FormatUint(val.Uint(), 10)
|
||||||
|
case Float32, Float64:
|
||||||
|
return strconv.FormatFloat(val.Float(), 'g', -1, 64)
|
||||||
|
case Complex64, Complex128:
|
||||||
|
c := val.Complex()
|
||||||
|
return strconv.FormatFloat(real(c), 'g', -1, 64) + "+" + strconv.FormatFloat(imag(c), 'g', -1, 64) + "i"
|
||||||
|
case String:
|
||||||
|
return val.String()
|
||||||
|
case Bool:
|
||||||
|
if val.Bool() {
|
||||||
|
return "true"
|
||||||
|
} else {
|
||||||
|
return "false"
|
||||||
|
}
|
||||||
|
case Pointer:
|
||||||
|
v := val
|
||||||
|
str = typ.String() + "("
|
||||||
|
if v.IsNil() {
|
||||||
|
str += "0"
|
||||||
|
} else {
|
||||||
|
str += "&" + valueToString(v.Elem())
|
||||||
|
}
|
||||||
|
str += ")"
|
||||||
|
return str
|
||||||
|
case Array, Slice:
|
||||||
|
v := val
|
||||||
|
str += typ.String()
|
||||||
|
str += "{"
|
||||||
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
if i > 0 {
|
||||||
|
str += ", "
|
||||||
|
}
|
||||||
|
str += valueToString(v.Index(i))
|
||||||
|
}
|
||||||
|
str += "}"
|
||||||
|
return str
|
||||||
|
case Map:
|
||||||
|
t := typ
|
||||||
|
str = t.String()
|
||||||
|
str += "{"
|
||||||
|
str += "<can't iterate on maps>"
|
||||||
|
str += "}"
|
||||||
|
return str
|
||||||
|
case Chan:
|
||||||
|
str = typ.String()
|
||||||
|
return str
|
||||||
|
case Struct:
|
||||||
|
t := typ
|
||||||
|
v := val
|
||||||
|
str += t.String()
|
||||||
|
str += "{"
|
||||||
|
for i, n := 0, v.NumField(); i < n; i++ {
|
||||||
|
if i > 0 {
|
||||||
|
str += ", "
|
||||||
|
}
|
||||||
|
str += valueToString(v.Field(i))
|
||||||
|
}
|
||||||
|
str += "}"
|
||||||
|
return str
|
||||||
|
case Interface:
|
||||||
|
return typ.String() + "(" + valueToString(val.Elem()) + ")"
|
||||||
|
case Func:
|
||||||
|
v := val
|
||||||
|
return typ.String() + "(" + strconv.FormatUint(uint64(v.Pointer()), 10) + ")"
|
||||||
|
default:
|
||||||
|
panic("valueToString: can't print type " + typ.String())
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче