MCPcopy Create free account
hub / github.com/canopyclimate/golive / FuzzTreeSerialization

Function FuzzTreeSerialization

internal/tmpl/tree_test.go:271–304  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

269}
270
271func FuzzTreeSerialization(f *testing.F) {
272 f.Fuzz(func(t *testing.T, seed int64, s string, n byte) {
273 if !utf8.ValidString(s) {
274 return
275 }
276 root := tmpl.NewTree()
277 trees := []*tmpl.Tree{root}
278 prng := rand.New(rand.NewSource(seed))
279 sub := func() string {
280 x := s
281 if len(x) == 0 {
282 return x
283 }
284 x = x[prng.Intn(len(x)):]
285 if len(x) == 0 {
286 return x
287 }
288 x = x[:prng.Intn(len(x))]
289 return x
290 }
291 for i := 0; i < int(n); i++ {
292 tree := trees[prng.Intn(len(trees))]
293 switch prng.Intn(3) {
294 case 0:
295 tree.AppendStatic(sub())
296 case 1:
297 tree.AppendDynamic(sub())
298 case 2:
299 trees = append(trees, tree.AppendSub())
300 }
301 }
302 root.WriteTo(io.Discard)
303 })
304}
305
306func BenchmarkWideStatic(b *testing.B) {
307 b.ReportAllocs()

Callers

nothing calls this directly

Calls 6

WriteToMethod · 0.95
NewTreeFunction · 0.92
AppendStaticMethod · 0.80
AppendDynamicMethod · 0.80
AppendSubMethod · 0.80
NewMethod · 0.45

Tested by

no test coverage detected