From 7ee9623f2b5d4685a91a51d0823275754b4d3a0a Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Sat, 4 Nov 2017 10:21:41 +0200 Subject: Filter matches as a final stage This simplifies the prediction logic writing, the predictor doesn't need to filter our according to line matching, instead it returns everything and the filtering is done at the end. This does not break current behavior. --- gocomplete/tests.go | 11 ++--------- gocomplete/tests_test.go | 27 --------------------------- 2 files changed, 2 insertions(+), 36 deletions(-) (limited to 'gocomplete') diff --git a/gocomplete/tests.go b/gocomplete/tests.go index a952dab..e755ae5 100644 --- a/gocomplete/tests.go +++ b/gocomplete/tests.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/posener/complete" - "github.com/posener/complete/match" ) var ( @@ -21,14 +20,8 @@ var ( // for test names use prefix of 'Test' or 'Example', and for benchmark // test names use 'Benchmark' func funcPredict(funcRegexp *regexp.Regexp) complete.Predictor { - return complete.PredictFunc(func(a complete.Args) (prediction []string) { - tests := funcNames(funcRegexp) - for _, t := range tests { - if match.Prefix(t, a.Last) { - prediction = append(prediction, t) - } - } - return + return complete.PredictFunc(func(a complete.Args) []string { + return funcNames(funcRegexp) }) } diff --git a/gocomplete/tests_test.go b/gocomplete/tests_test.go index 6799157..150e2e2 100644 --- a/gocomplete/tests_test.go +++ b/gocomplete/tests_test.go @@ -22,38 +22,11 @@ func TestPredictions(t *testing.T) { predictor: predictTest, want: []string{"TestPredictions", "Example"}, }, - { - name: "predict tests not found", - predictor: predictTest, - last: "X", - }, { name: "predict benchmark ok", predictor: predictBenchmark, want: []string{"BenchmarkFake"}, }, - { - name: "predict benchmarks not found", - predictor: predictBenchmark, - last: "X", - }, - { - name: "predict local ok", - predictor: complete.PredictFunc(predictPackages), - last: ".", - want: []string{"./"}, - }, - { - name: "predict system ok", - predictor: complete.PredictFunc(predictPackages), - last: "github.com/posener/complete/goc", - want: []string{"github.com/posener/complete/gocomplete/"}, - }, - { - name: "predict packages not found", - predictor: complete.PredictFunc(predictPackages), - last: "X", - }, } for _, tt := range tests { -- cgit v1.2.3