(f *testing.F)
| 269 | } |
| 270 | |
| 271 | func 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 | |
| 306 | func BenchmarkWideStatic(b *testing.B) { |
| 307 | b.ReportAllocs() |
nothing calls this directly
no test coverage detected