(complexity int, rng *rand.Rand)
| 51 | } |
| 52 | |
| 53 | func doRandomJSON(complexity int, rng *rand.Rand) interface{} { |
| 54 | if complexity <= 0 || rng.Intn(10) == 0 { |
| 55 | switch rng.Intn(5) { |
| 56 | case 0: |
| 57 | return randomJSONString(rng) |
| 58 | case 1: |
| 59 | return randomJSONNumber(rng) |
| 60 | case 2: |
| 61 | return true |
| 62 | case 3: |
| 63 | return false |
| 64 | case 4: |
| 65 | return nil |
| 66 | } |
| 67 | } |
| 68 | complexity-- |
| 69 | switch rng.Intn(3) { |
| 70 | case 0: |
| 71 | result := make([]interface{}, 0) |
| 72 | for complexity > 0 { |
| 73 | amount := 1 + rng.Intn(complexity) |
| 74 | complexity -= amount |
| 75 | result = append(result, doRandomJSON(amount, rng)) |
| 76 | } |
| 77 | return result |
| 78 | case 1: |
| 79 | result := make(map[string]interface{}) |
| 80 | for complexity > 0 { |
| 81 | amount := 1 + rng.Intn(complexity) |
| 82 | complexity -= amount |
| 83 | result[randomJSONString(rng).(string)] = doRandomJSON(amount, rng) |
| 84 | } |
| 85 | return result |
| 86 | default: |
| 87 | j, _ := Random(complexity, rng) |
| 88 | encoding, _ := EncodeJSON(nil, j) |
| 89 | encoded, _ := newEncodedFromRoot(encoding) |
| 90 | return encoded |
| 91 | } |
| 92 | } |
no test coverage detected
searching dependent graphs…