github.com/chriswalz/complete/v3@v3.0.13/gocomplete/tests_test.go (about) 1 package main 2 3 import ( 4 "os" 5 "sort" 6 "testing" 7 8 "github.com/chriswalz/complete/v3" 9 ) 10 11 func TestPredictions(t *testing.T) { 12 t.Parallel() 13 14 tests := []struct { 15 name string 16 predictor complete.Predictor 17 prefix string 18 want []string 19 }{ 20 { 21 name: "predict tests ok", 22 predictor: predictTest, 23 want: []string{"TestPredictions", "Example"}, 24 }, 25 { 26 name: "predict benchmark ok", 27 predictor: predictBenchmark, 28 want: []string{"BenchmarkFake"}, 29 }, 30 } 31 32 for _, tt := range tests { 33 t.Run(tt.name, func(t *testing.T) { 34 got := tt.predictor.Predict(tt.prefix) 35 if !equal(got, tt.want) { 36 t.Errorf("Failed %s: got: %q, want: %q", t.Name(), got, tt.want) 37 } 38 }) 39 } 40 } 41 42 func BenchmarkFake(b *testing.B) {} 43 44 func Example() { 45 os.Setenv("COMP_LINE", "go ru") 46 os.Setenv("COMP_POINT", "5") 47 main() 48 // output: run 49 } 50 51 func equal(s1, s2 []string) bool { 52 sort.Strings(s1) 53 sort.Strings(s2) 54 if len(s1) != len(s2) { 55 return false 56 } 57 for i := range s1 { 58 if s1[i] != s2[i] { 59 return false 60 } 61 } 62 return true 63 }