File: tests_test.go

package info (click to toggle)
golang-github-posener-complete 1.1%2Bgit20180108.57878c9-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 200 kB
  • sloc: sh: 9; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

import (
	"os"
	"sort"
	"testing"

	"github.com/posener/complete"
)

func TestPredictions(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name      string
		predictor complete.Predictor
		last      string
		want      []string
	}{
		{
			name:      "predict tests ok",
			predictor: predictTest,
			want:      []string{"TestPredictions", "Example"},
		},
		{
			name:      "predict benchmark ok",
			predictor: predictBenchmark,
			want:      []string{"BenchmarkFake"},
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			a := complete.Args{Last: tt.last}
			got := tt.predictor.Predict(a)
			if !equal(got, tt.want) {
				t.Errorf("Failed %s: got: %q, want: %q", t.Name(), got, tt.want)
			}
		})
	}
}

func BenchmarkFake(b *testing.B) {}

func Example() {
	os.Setenv("COMP_LINE", "go ru")
	main()
	// output: run

}

func equal(s1, s2 []string) bool {
	sort.Strings(s1)
	sort.Strings(s2)
	if len(s1) != len(s2) {
		return false
	}
	for i := range s1 {
		if s1[i] != s2[i] {
			return false
		}
	}
	return true
}