github.com/boyter/gocodewalker@v1.3.2/gitignore_test.go (about) 1 // SPDX-License-Identifier: MIT OR Unlicense 2 3 package gocodewalker 4 5 import ( 6 "github.com/boyter/gocodewalker/go-gitignore" 7 "path/filepath" 8 "strings" 9 "testing" 10 ) 11 12 func TestGitIgnore(t *testing.T) { 13 testcases := []string{ 14 `/`, 15 `\`, 16 `"`, 17 `.`, 18 } 19 20 abs, _ := filepath.Abs(".") 21 for _, te := range testcases { 22 gitignore.New(strings.NewReader(te), abs, nil) 23 } 24 } 25 26 func FuzzTestGitIgnore(f *testing.F) { 27 testcases := []string{ 28 "", 29 `\`, 30 `'`, 31 `#`, 32 "/", 33 "README.md", 34 `README.md 35 /`, 36 `*.[oa] 37 *.html 38 *.min.js 39 40 !foo*.html 41 foo-excl.html 42 43 vmlinux* 44 45 \!important!.txt 46 47 log/*.log 48 !/log/foo.log 49 50 **/logdir/log 51 **/foodir/bar 52 exclude/** 53 54 !findthis* 55 56 **/hide/** 57 subdir/subdir2/ 58 59 /rootsubdir/ 60 61 dirpattern/ 62 63 README.md 64 `, 65 } 66 67 for _, tc := range testcases { 68 f.Add(tc) // Use f.Add to provide a seed corpus 69 } 70 71 abs, _ := filepath.Abs(".") 72 f.Fuzz(func(t *testing.T, c string) { 73 gitignore.New(strings.NewReader(c), abs, nil) 74 }) 75 }