File: eface_test.go

package info (click to toggle)
golang-github-json-iterator-go 1.1.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 916 kB
  • sloc: sh: 19; makefile: 3
file content (78 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package test

func init() {
	var pEFace = func(val interface{}) *interface{} {
		return &val
	}
	var pInt = func(val int) *int {
		return &val
	}
	unmarshalCases = append(unmarshalCases, unmarshalCase{
		ptr:   (**interface{})(nil),
		input: `"hello"`,
	}, unmarshalCase{
		ptr:   (**interface{})(nil),
		input: `1e1`,
	}, unmarshalCase{
		ptr:   (**interface{})(nil),
		input: `1.0e1`,
	}, unmarshalCase{
		ptr:   (*[]interface{})(nil),
		input: `[1.0e1]`,
	}, unmarshalCase{
		ptr: (*struct {
			Field interface{}
		})(nil),
		input: `{"field":"hello"}`,
	}, unmarshalCase{
		obj: func() interface{} {
			type TestData struct {
				Name string `json:"name"`
			}
			o := &TestData{}
			return &o
		},
		input: `{"name":"value"}`,
	}, unmarshalCase{
		obj: func() interface{} {
			b := true
			return &struct {
				Field interface{} `json:"field"`
			}{&b}
		},
		input: `{"field": null}`,
	}, unmarshalCase{
		obj: func() interface{} {
			var pb *bool
			return &struct {
				Field interface{} `json:"field"`
			}{&pb}
		},
		input: `{"field": null}`,
	}, unmarshalCase{
		obj: func() interface{} {
			b := true
			pb := &b
			return &struct {
				Field interface{} `json:"field"`
			}{&pb}
		},
		input: `{"field": null}`,
	})
	marshalCases = append(marshalCases,
		pEFace("hello"),
		struct {
			Field interface{}
		}{"hello"},
		struct {
			Field interface{}
		}{struct {
			field chan int
		}{}},
		struct {
			Field interface{}
		}{struct {
			Field *int
		}{pInt(100)}},
	)
}