Squashed 'backend/goldmark/' content from commit 379bf24
git-subtree-dir: backend/goldmark git-subtree-split: 379bf24a47e6ef07f34d7536aead86d8792ac300
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
"github.com/yuin/goldmark/util"
|
||||
)
|
||||
|
||||
func fuzz(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, orig string) {
|
||||
markdown := goldmark.New(
|
||||
goldmark.WithParserOptions(
|
||||
parser.WithAutoHeadingID(),
|
||||
parser.WithAttribute(),
|
||||
),
|
||||
goldmark.WithRendererOptions(
|
||||
html.WithUnsafe(),
|
||||
html.WithXHTML(),
|
||||
),
|
||||
goldmark.WithExtensions(
|
||||
extension.DefinitionList,
|
||||
extension.Footnote,
|
||||
extension.GFM,
|
||||
extension.Typographer,
|
||||
extension.Linkify,
|
||||
extension.Table,
|
||||
extension.TaskList,
|
||||
),
|
||||
)
|
||||
var b bytes.Buffer
|
||||
if err := markdown.Convert(util.StringToReadOnlyBytes(orig), &b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzDefault(f *testing.F) {
|
||||
bs, err := os.ReadFile("../_test/spec.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var testCases []map[string]any
|
||||
if err := json.Unmarshal(bs, &testCases); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, c := range testCases {
|
||||
f.Add(c["markdown"])
|
||||
}
|
||||
fuzz(f)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func FuzzOss(f *testing.F) {
|
||||
fuzz(f)
|
||||
}
|
||||
Reference in New Issue
Block a user