.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.1.1 / pattern / fuzz.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/honnef.co/go/tools@v0.1.1/pattern/fuzz.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/honnef.co/go/tools@v0.1.1/pattern/fuzz.go
new file mode 100644 (file)
index 0000000..52e7df9
--- /dev/null
@@ -0,0 +1,50 @@
+// +build gofuzz
+
+package pattern
+
+import (
+       "go/ast"
+       goparser "go/parser"
+       "go/token"
+       "os"
+       "path/filepath"
+       "strings"
+)
+
+var files []*ast.File
+
+func init() {
+       fset := token.NewFileSet()
+       filepath.Walk("/usr/lib/go/src", func(path string, info os.FileInfo, err error) error {
+               if err != nil {
+                       // XXX error handling
+                       panic(err)
+               }
+               if !strings.HasSuffix(path, ".go") {
+                       return nil
+               }
+               f, err := goparser.ParseFile(fset, path, nil, 0)
+               if err != nil {
+                       return nil
+               }
+               files = append(files, f)
+               return nil
+       })
+}
+
+func Fuzz(data []byte) int {
+       p := &Parser{}
+       pat, err := p.Parse(string(data))
+       if err != nil {
+               if strings.Contains(err.Error(), "internal error") {
+                       panic(err)
+               }
+               return 0
+       }
+       _ = pat.Root.String()
+
+       for _, f := range files {
+               Match(pat.Root, f)
+       }
+       return 1
+}