github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/jsoni/value_tests/eface_test.go (about) 1 package test 2 3 func init() { 4 pEFace := func(val interface{}) *interface{} { 5 return &val 6 } 7 pInt := func(val int) *int { 8 return &val 9 } 10 unmarshalCases = append(unmarshalCases, unmarshalCase{ 11 ptr: (**interface{})(nil), 12 input: `"hello"`, 13 }, unmarshalCase{ 14 ptr: (**interface{})(nil), 15 input: `1e1`, 16 }, unmarshalCase{ 17 ptr: (**interface{})(nil), 18 input: `1.0e1`, 19 }, unmarshalCase{ 20 ptr: (*[]interface{})(nil), 21 input: `[1.0e1]`, 22 }, unmarshalCase{ 23 ptr: (*struct { 24 Field interface{} 25 })(nil), 26 input: `{"field":"hello"}`, 27 }, unmarshalCase{ 28 obj: func() interface{} { 29 type TestData struct { 30 Name string `json:"name"` 31 } 32 o := &TestData{} 33 return &o 34 }, 35 input: `{"name":"value"}`, 36 }, unmarshalCase{ 37 obj: func() interface{} { 38 b := true 39 return &struct { 40 Field interface{} `json:"field"` 41 }{&b} 42 }, 43 input: `{"field": null}`, 44 }, unmarshalCase{ 45 obj: func() interface{} { 46 var pb *bool 47 return &struct { 48 Field interface{} `json:"field"` 49 }{&pb} 50 }, 51 input: `{"field": null}`, 52 }, unmarshalCase{ 53 obj: func() interface{} { 54 b := true 55 pb := &b 56 return &struct { 57 Field interface{} `json:"field"` 58 }{&pb} 59 }, 60 input: `{"field": null}`, 61 }) 62 marshalCases = append(marshalCases, 63 pEFace("hello"), 64 struct { 65 Field interface{} 66 }{"hello"}, 67 struct { 68 Field interface{} 69 }{struct { 70 field chan int 71 }{}}, 72 struct { 73 Field interface{} 74 }{struct { 75 Field *int 76 }{pInt(100)}}, 77 ) 78 }