MCPcopy Index your code
hub / github.com/cheat/cheat / FuzzParse

Function FuzzParse

internal/sheet/parse_fuzz_test.go:10–100  ·  view source on GitHub ↗

FuzzParse tests the parse function with fuzzing to uncover edge cases and potential panics in YAML frontmatter parsing

(f *testing.F)

Source from the content-addressed store, hash-verified

8// FuzzParse tests the parse function with fuzzing to uncover edge cases
9// and potential panics in YAML frontmatter parsing
10func FuzzParse(f *testing.F) {
11 // Add seed corpus with various valid and edge case inputs
12 // Valid frontmatter
13 f.Add("---\nsyntax: go\n---\nContent")
14 f.Add("---\ntags: [a, b]\n---\n")
15 f.Add("---\nsyntax: bash\ntags: [linux, shell]\n---\n#!/bin/bash\necho hello")
16
17 // No frontmatter
18 f.Add("No frontmatter here")
19 f.Add("")
20 f.Add("Just plain text\nwith multiple lines")
21
22 // Edge cases with delimiters
23 f.Add("---")
24 f.Add("---\n")
25 f.Add("---\n---")
26 f.Add("---\n---\n")
27 f.Add("---\n---\n---")
28 f.Add("---\n---\n---\n---")
29 f.Add("------\n------")
30
31 // Invalid YAML
32 f.Add("---\n{invalid yaml\n---\n")
33 f.Add("---\nsyntax: \"unclosed quote\n---\n")
34 f.Add("---\ntags: [a, b,\n---\n")
35
36 // Windows line endings
37 f.Add("---\r\nsyntax: go\r\n---\r\nContent")
38 f.Add("---\r\n---\r\n")
39
40 // Mixed line endings
41 f.Add("---\nsyntax: go\r\n---\nContent")
42 f.Add("---\r\nsyntax: go\n---\r\nContent")
43
44 // Unicode and special characters
45 f.Add("---\ntags: [emoji, 🎉]\n---\n")
46 f.Add("---\nsyntax: 中文\n---\n")
47 f.Add("---\ntags: [\x00, \x01]\n---\n")
48
49 // Very long inputs
50 f.Add("---\ntags: [" + strings.Repeat("a,", 1000) + "a]\n---\n")
51 f.Add("---\n" + strings.Repeat("field: value\n", 1000) + "---\n")
52
53 // Nested structures
54 f.Add("---\ntags:\n - nested\n - list\n---\n")
55 f.Add("---\nmeta:\n author: test\n version: 1.0\n---\n")
56
57 f.Fuzz(func(t *testing.T, input string) {
58 // The parse function should never panic, regardless of input
59 func() {
60 defer func() {
61 if r := recover(); r != nil {
62 t.Errorf("parse panicked with input %q: %v", input, r)
63 }
64 }()
65
66 fm, text, err := parse(input)
67

Callers

nothing calls this directly

Calls 1

parseFunction · 0.85

Tested by

no test coverage detected