diff options
Diffstat (limited to 'tests/fuzz/profile/remembering.go')
| -rw-r--r-- | tests/fuzz/profile/remembering.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/fuzz/profile/remembering.go b/tests/fuzz/profile/remembering.go new file mode 100644 index 0000000..aab4ac4 --- /dev/null +++ b/tests/fuzz/profile/remembering.go @@ -0,0 +1,76 @@ +package remembering + +import ( + "os" + "reflect" + "strings" + "testing" + "testing/internal/testdeps" +) + + + +func fn(f *testing.F) { + f.Add("0 profile a\n1 profile b\n", "c\nd", "a") + f.Add("", "x", "x") + f.Fuzz(func( + t *testing.T, + content string, + input string, + choice string, + ) { + profile := parseProfile(content) + again := parseProfile(serializeProfile(profile)) + if !reflect.DeepEqual(again, profile) { + t.Fatalf( + "roundtrip: %#v != %#v", + again, profile, + ) + } + + if choice == "" || + strings.Contains(choice, "\n") { + return + } + lines := splitLines(input) + next := nextProfile(profile, lines, choice) + + found := false + for _, entry := range next { + if entry.text == choice { + found = true + } + } + if !found { + t.Fatalf( + "pick %q not learnt in %#v", + choice, next, + ) + } + + reNext := parseProfile(serializeProfile(next)) + if !reflect.DeepEqual(reNext, next) { + t.Fatalf( + "next roundtrip: %#v != %#v", + reNext, next, + ) + } + }) +} + + + +func MainTest() { + fuzzTargets := []testing.InternalFuzzTarget{ + {"fn", fn}, + } + + deps := testdeps.TestDeps{} + tests := []testing.InternalTest {} + benchmarks := []testing.InternalBenchmark{} + examples := []testing.InternalExample {} + m := testing.MainStart( + deps, tests, benchmarks, fuzzTargets, examples, + ) + os.Exit(m.Run()) +} |
