MCPcopy Create free account
hub / github.com/segmentio/encoding / TestMain

Function TestMain

json/json_test.go:39–76  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

37)
38
39func TestMain(m *testing.M) {
40 var pkg string
41 flag.StringVar(&pkg, "package", ".", "The name of the package to test (encoding/json, or default to this package)")
42 flag.BoolVar(&escapeHTML, "escapehtml", false, "Whether to enable HTML escaping or not")
43 flag.Parse()
44
45 switch pkg {
46 case "encoding/json":
47 buf := &buffer{}
48 enc := json.NewEncoder(buf)
49 enc.SetEscapeHTML(escapeHTML)
50
51 marshal = func(b []byte, v any) ([]byte, error) {
52 buf.data = b
53 err := enc.Encode(v)
54 return buf.data, err
55 }
56
57 unmarshal = json.Unmarshal
58
59 default:
60 flags := AppendFlags(0)
61 if escapeHTML {
62 flags |= EscapeHTML
63 }
64
65 marshal = func(b []byte, v any) ([]byte, error) {
66 return Append(b, v, flags)
67 }
68
69 unmarshal = func(b []byte, v any) error {
70 _, err := Parse(b, v, ZeroCopy)
71 return err
72 }
73 }
74
75 os.Exit(m.Run())
76}
77
78type point struct {
79 X int `json:"x"`

Callers

nothing calls this directly

Calls 5

SetEscapeHTMLMethod · 0.95
EncodeMethod · 0.95
AppendFlagsTypeAlias · 0.85
AppendFunction · 0.70
ParseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…