MCPcopy Create free account
hub / github.com/dolthub/doltgresql / doRandomJSON

Function doRandomJSON

postgres/parser/json/random.go:67–106  ·  view source on GitHub ↗
(complexity int, rng *rand.Rand)

Source from the content-addressed store, hash-verified

65}
66
67func 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}

Callers 1

RandomFunction · 0.85

Calls 6

randomJSONStringFunction · 0.85
randomJSONNumberFunction · 0.85
EncodeJSONFunction · 0.85
newEncodedFromRootFunction · 0.85
RandomFunction · 0.70
IntnMethod · 0.65

Tested by

no test coverage detected