github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/analysis/code/code_test.go (about) 1 package code 2 3 import "testing" 4 5 var constraintsFromNameTests = []struct { 6 in string 7 out string 8 }{ 9 {"foo.go", ""}, 10 {"foo_windows.go", "windows"}, 11 {"foo_unix.go", ""}, 12 {"foo_windows_amd64.go", "windows && amd64"}, 13 {"foo_amd64.go", "amd64"}, 14 {"foo_windows_nonsense.go", ""}, 15 {"foo_nonsense_amd64.go", "amd64"}, 16 {"foo_nonsense_windows.go", "windows"}, 17 {"foo_nonsense_windows_amd64.go", "amd64"}, 18 {"foo_windows_test.go", "windows"}, 19 {"linux.go", ""}, 20 {"linux_amd64.go", "amd64"}, 21 {"amd64_linux.go", "linux"}, 22 {"amd64.go", ""}, 23 } 24 25 func TestConstraintsFromName(t *testing.T) { 26 for _, tc := range constraintsFromNameTests { 27 expr := constraintsFromName(tc.in) 28 var out string 29 if expr != nil { 30 out = expr.String() 31 } 32 if out != tc.out { 33 t.Errorf("constraintsFromName(%q) == %q, expected %q", tc.in, out, tc.out) 34 } 35 } 36 } 37 38 func FuzzConstraintsFromName(f *testing.F) { 39 for _, tc := range constraintsFromNameTests { 40 f.Add(tc.in) 41 } 42 43 f.Fuzz(func(t *testing.T, name string) { 44 constraintsFromName(name) 45 }) 46 }