MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / subdocument

Method subdocument

pkg/util/json/contains_testers.go:107–132  ·  view source on GitHub ↗
(isRoot bool, rng *rand.Rand)

Source from the content-addressed store, hash-verified

105func (j jsonString) subdocument(_ bool, _ *rand.Rand) JSON { return j }
106
107func (j jsonArray) subdocument(isRoot bool, rng *rand.Rand) JSON {
108 // Root arrays contain their scalar elements.
109 if isRoot && rng.Intn(5) == 0 {
110 idx := rng.Intn(len(j))
111 if j[idx].isScalar() {
112 return j[idx]
113 }
114 }
115 result := make(jsonArray, 0)
116 i := 0
117 for i < len(j) {
118 if rng.Intn(2) == 0 {
119 result = append(result, j[i].(containsTester).subdocument(false /* isRoot */, rng))
120 }
121 if rng.Intn(2) == 0 {
122 i++
123 }
124 }
125 // Shuffle the slice.
126 for i := range result {
127 j := rng.Intn(i + 1)
128 result[i], result[j] = result[j], result[i]
129 }
130
131 return result
132}
133
134func (j jsonObject) subdocument(_ bool, rng *rand.Rand) JSON {
135 result := make(jsonObject, 0)

Callers

nothing calls this directly

Calls 3

IntnMethod · 0.65
isScalarMethod · 0.65
subdocumentMethod · 0.65

Tested by

no test coverage detected