github.com/linux4life798/complete@v1.1.1/gocomplete/tests_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"sort"
     6  	"testing"
     7  
     8  	"github.com/posener/complete"
     9  )
    10  
    11  func TestPredictions(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	tests := []struct {
    15  		name      string
    16  		predictor complete.Predictor
    17  		last      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  			a := complete.Args{Last: tt.last}
    35  			got := tt.predictor.Predict(a)
    36  			if !equal(got, tt.want) {
    37  				t.Errorf("Failed %s: got: %q, want: %q", t.Name(), got, tt.want)
    38  			}
    39  		})
    40  	}
    41  }
    42  
    43  func BenchmarkFake(b *testing.B) {}
    44  
    45  func Example() {
    46  	os.Setenv("COMP_LINE", "go ru")
    47  	main()
    48  	// output: run
    49  
    50  }
    51  
    52  func equal(s1, s2 []string) bool {
    53  	sort.Strings(s1)
    54  	sort.Strings(s2)
    55  	if len(s1) != len(s2) {
    56  		return false
    57  	}
    58  	for i := range s1 {
    59  		if s1[i] != s2[i] {
    60  			return false
    61  		}
    62  	}
    63  	return true
    64  }