(complexity int, rng *rand.Rand)
| 65 | } |
| 66 | |
| 67 | func doRandomJSON(complexity int, rng *rand.Rand) interface{} { |
| 68 | if complexity <= 0 || rng.Intn(10) == 0 { |
| 69 | switch rng.Intn(5) { |
| 70 | case 0: |
| 71 | return randomJSONString(rng) |
| 72 | case 1: |
| 73 | return randomJSONNumber(rng) |
| 74 | case 2: |
| 75 | return true |
| 76 | case 3: |
| 77 | return false |
| 78 | case 4: |
| 79 | return nil |
| 80 | } |
| 81 | } |
| 82 | complexity-- |
| 83 | switch rng.Intn(3) { |
| 84 | case 0: |
| 85 | result := make([]interface{}, 0) |
| 86 | for complexity > 0 { |
| 87 | amount := 1 + rng.Intn(complexity) |
| 88 | complexity -= amount |
| 89 | result = append(result, doRandomJSON(amount, rng)) |
| 90 | } |
| 91 | return result |
| 92 | case 1: |
| 93 | result := make(map[string]interface{}) |
| 94 | for complexity > 0 { |
| 95 | amount := 1 + rng.Intn(complexity) |
| 96 | complexity -= amount |
| 97 | result[randomJSONString(rng).(string)] = doRandomJSON(amount, rng) |
| 98 | } |
| 99 | return result |
| 100 | default: |
| 101 | j, _ := Random(complexity, rng) |
| 102 | encoding, _ := EncodeJSON(nil, j) |
| 103 | encoded, _ := newEncodedFromRoot(encoding) |
| 104 | return encoded |
| 105 | } |
| 106 | } |
no test coverage detected