genObject emits an object with 0–5 entries. Keys are drawn from a set that includes the dangerous cases: empty-string "", unicode (\uXXXX), long, and escaped special characters.
(r *rand.Rand, depth int, buf *[]byte)
| 203 | // that includes the dangerous cases: empty-string "", unicode (\uXXXX), |
| 204 | // long, and escaped special characters. |
| 205 | func genObject(r *rand.Rand, depth int, buf *[]byte) { |
| 206 | *buf = append(*buf, '{') |
| 207 | n := r.Intn(6) // 0..5 entries |
| 208 | for i := 0; i < n; i++ { |
| 209 | if i > 0 { |
| 210 | *buf = append(*buf, ',') |
| 211 | } |
| 212 | genKey(r, buf) |
| 213 | *buf = append(*buf, ':') |
| 214 | genValue(r, depth+1, buf) |
| 215 | } |
| 216 | *buf = append(*buf, '}') |
| 217 | } |
| 218 | |
| 219 | // genArray emits an array with 0–5 elements (including the empty array []). |
| 220 | func genArray(r *rand.Rand, depth int, buf *[]byte) { |