(m *testing.M)
| 37 | ) |
| 38 | |
| 39 | func 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 | |
| 78 | type point struct { |
| 79 | X int `json:"x"` |
nothing calls this directly
no test coverage detected
searching dependent graphs…