gitee.com/quant1x/gox@v1.7.6/encoding/binary/cstruct/tests/slice_ignore_nil_test.go (about) 1 package tests 2 3 import ( 4 "gitee.com/quant1x/gox/encoding/binary/cstruct" 5 "testing" 6 ) 7 8 type mystruct_sint12 struct { 9 F1 int8 10 } 11 12 type mystruct_sint10 struct { 13 F2 []*mystruct_sint12 14 F1 int32 15 F3 []*mystruct_sint12 16 } 17 18 type mystruct_sint9 struct { 19 F90 []*mystruct_sint10 20 } 21 22 func Test_LE_sint9(t *testing.T) { 23 cstruct.OptionSliceIgnoreNil = true 24 b1 := []*mystruct_sint12{&mystruct_sint12{1}, &mystruct_sint12{2}, &mystruct_sint12{3}, &mystruct_sint12{4}} 25 b2 := []*mystruct_sint12{} 26 b3 := []*mystruct_sint12{&mystruct_sint12{1}, &mystruct_sint12{2}} 27 { 28 a := &mystruct_sint9{} 29 a.F90 = []*mystruct_sint10{&mystruct_sint10{nil, 1, nil}, &mystruct_sint10{nil, 2, nil}, &mystruct_sint10{b3, 3, b1}} 30 test7(t, a) 31 } 32 { 33 a := &mystruct_sint9{} 34 a.F90 = []*mystruct_sint10{&mystruct_sint10{b1, 1, b3}} 35 test7(t, a) 36 } 37 { 38 a := &mystruct_sint9{} 39 a.F90 = []*mystruct_sint10{} 40 test7(t, a) 41 } 42 { 43 a := &mystruct_sint9{} 44 a.F90 = []*mystruct_sint10{&mystruct_sint10{b1, 1, b2}} 45 test7(t, a) 46 47 } 48 { 49 a := &mystruct_sint9{} 50 a.F90 = []*mystruct_sint10{&mystruct_sint10{b2, 1, b1}} 51 test7(t, a) 52 } 53 { 54 a := &mystruct_sint9{} 55 a.F90 = []*mystruct_sint10{&mystruct_sint10{b1, 1, b2}, &mystruct_sint10{b2, 1, b1}, &mystruct_sint10{b2, 1, b1}, &mystruct_sint10{b2, 1, b1}} 56 test7(t, a) 57 58 } 59 } 60 61 func test7(t *testing.T, a *mystruct_sint9) { 62 buf_l, _ := cstruct.Pack(a) 63 b := &mystruct_sint9{} 64 t.Log(buf_l) 65 if err := cstruct.Unpack(buf_l, b); err != nil { 66 t.Log(err) 67 t.Error("出错啦!") 68 return 69 } 70 t.Log(b) 71 }