(rng *rand.Rand, cfg randConfig)
| 149 | } |
| 150 | |
| 151 | func doRandomJSON(rng *rand.Rand, cfg randConfig) interface{} { |
| 152 | if cfg.complexity <= 0 || rng.Intn(cfg.complexity) == 0 { |
| 153 | switch rng.Intn(5) { |
| 154 | case 0: |
| 155 | return randomJSONString(rng, cfg) |
| 156 | case 1: |
| 157 | return randomJSONNumber(rng) |
| 158 | case 2: |
| 159 | return true |
| 160 | case 3: |
| 161 | return false |
| 162 | case 4: |
| 163 | return nil |
| 164 | } |
| 165 | } |
| 166 | cfg.complexity-- |
| 167 | switch rng.Intn(3) { |
| 168 | case 0: |
| 169 | result := make([]interface{}, 0) |
| 170 | for cfg.complexity > 0 { |
| 171 | amount := 1 + rng.Intn(cfg.complexity) |
| 172 | cfg.complexity -= amount |
| 173 | result = append(result, doRandomJSON(rng, cfg)) |
| 174 | } |
| 175 | return result |
| 176 | case 1: |
| 177 | result := make(map[string]interface{}) |
| 178 | for cfg.complexity > 0 { |
| 179 | amount := 1 + rng.Intn(cfg.complexity) |
| 180 | cfg.complexity -= amount |
| 181 | result[randomJSONString(rng, objectKeyConfig)] = doRandomJSON(rng, cfg) |
| 182 | } |
| 183 | return result |
| 184 | default: |
| 185 | j, _ := MakeJSON(doRandomJSON(rng, cfg)) |
| 186 | encoding, _ := EncodeJSON(nil, j) |
| 187 | encoded, _ := newEncodedFromRoot(encoding) |
| 188 | return encoded |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // AsStringWithErrorChance returns string representation of JSON object, |
| 193 | // but allows up to specified chance that the returned string will contain |
no test coverage detected
searching dependent graphs…