oracleRandomJSONValue builds a random nested Go value suitable for json.Marshal. It is intentionally richer than property_test.go's generator: it emits empty containers, large integers, unicode strings, and mixed types at every depth.
(r *mathrand.Rand, depth int)
| 161 | // it emits empty containers, large integers, unicode strings, and mixed |
| 162 | // types at every depth. |
| 163 | func oracleRandomJSONValue(r *mathrand.Rand, depth int) interface{} { |
| 164 | if depth <= 0 { |
| 165 | switch r.Intn(7) { |
| 166 | case 0: |
| 167 | // Large-int bias: pick from boundary table half the time, |
| 168 | // random int64 the other half. |
| 169 | if r.Intn(2) == 0 { |
| 170 | return oracleLargeInts[r.Intn(len(oracleLargeInts))] |
| 171 | } |
| 172 | return r.Int63() |
| 173 | case 1: |
| 174 | // Random float, including subnormals and large magnitudes. |
| 175 | switch r.Intn(4) { |
| 176 | case 0: |
| 177 | return r.Float64() |
| 178 | case 1: |
| 179 | return -r.Float64() |
| 180 | case 2: |
| 181 | return float64(r.Int63()) * 1e10 |
| 182 | default: |
| 183 | return r.NormFloat64() |
| 184 | } |
| 185 | case 2: |
| 186 | return r.Intn(2) == 0 |
| 187 | case 3: |
| 188 | return nil |
| 189 | case 4: |
| 190 | return oracleUnicodeStrings[r.Intn(len(oracleUnicodeStrings))] |
| 191 | case 5: |
| 192 | // Small integer (common case). |
| 193 | return r.Intn(100) |
| 194 | default: |
| 195 | return oracleLargeInts[r.Intn(len(oracleLargeInts))] |
| 196 | } |
| 197 | } |
| 198 | switch r.Intn(4) { |
| 199 | case 0: |
| 200 | return oracleUnicodeStrings[r.Intn(len(oracleUnicodeStrings))] |
| 201 | case 1: |
| 202 | // Array — half the time empty. |
| 203 | if r.Intn(5) == 0 { |
| 204 | return []interface{}{} |
| 205 | } |
| 206 | n := r.Intn(5) + 1 |
| 207 | arr := make([]interface{}, n) |
| 208 | for i := range arr { |
| 209 | arr[i] = oracleRandomJSONValue(r, depth-1) |
| 210 | } |
| 211 | return arr |
| 212 | default: |
| 213 | // Object — half the time empty. |
| 214 | if r.Intn(5) == 0 { |
| 215 | return map[string]interface{}{} |
| 216 | } |
| 217 | n := r.Intn(5) + 1 |
| 218 | obj := make(map[string]interface{}, n) |
| 219 | used := map[string]bool{} |
| 220 | for i := 0; i < n; i++ { |
no test coverage detected