From 8724aaf18312e54750540a9578e00d61b1c545d8 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Thu, 14 Nov 2019 06:51:44 +0200 Subject: V2 --- match/match.go | 39 ---------------- match/match_test.go | 129 ---------------------------------------------------- 2 files changed, 168 deletions(-) delete mode 100644 match/match.go delete mode 100644 match/match_test.go (limited to 'match') diff --git a/match/match.go b/match/match.go deleted file mode 100644 index b5f1814..0000000 --- a/match/match.go +++ /dev/null @@ -1,39 +0,0 @@ -// Package match contains matchers that decide if to apply completion. -// -// This package is deprecated. -package match - -import "strings" - -// Match matches two strings -// it is used for comparing a term to the last typed -// word, the prefix, and see if it is a possible auto complete option. -// -// Deprecated. -type Match func(term, prefix string) bool - -// Prefix is a simple Matcher, if the word is it's prefix, there is a match -// Match returns true if a has the prefix as prefix -// -// Deprecated. -func Prefix(long, prefix string) bool { - return strings.HasPrefix(long, prefix) -} - -// File returns true if prefix can match the file -// -// Deprecated. -func File(file, prefix string) bool { - // special case for current directory completion - if file == "./" && (prefix == "." || prefix == "") { - return true - } - if prefix == "." && strings.HasPrefix(file, ".") { - return true - } - - file = strings.TrimPrefix(file, "./") - prefix = strings.TrimPrefix(prefix, "./") - - return strings.HasPrefix(file, prefix) -} diff --git a/match/match_test.go b/match/match_test.go deleted file mode 100644 index b5a0d87..0000000 --- a/match/match_test.go +++ /dev/null @@ -1,129 +0,0 @@ -package match - -import ( - "fmt" - "os" - "testing" -) - -func TestMatch(t *testing.T) { - t.Parallel() - - // Change to tests directory for testing completion of - // files and directories - err := os.Chdir("../tests") - if err != nil { - panic(err) - } - - type matcherTest struct { - prefix string - want bool - } - - tests := []struct { - m Match - long string - tests []matcherTest - }{ - { - m: Prefix, - long: "abcd", - tests: []matcherTest{ - {prefix: "", want: true}, - {prefix: "ab", want: true}, - {prefix: "ac", want: false}, - }, - }, - { - m: Prefix, - long: "", - tests: []matcherTest{ - {prefix: "ac", want: false}, - {prefix: "", want: true}, - }, - }, - { - m: File, - long: "file.txt", - tests: []matcherTest{ - {prefix: "", want: true}, - {prefix: "f", want: true}, - {prefix: "./f", want: true}, - {prefix: "./.", want: false}, - {prefix: "file.", want: true}, - {prefix: "./file.", want: true}, - {prefix: "file.txt", want: true}, - {prefix: "./file.txt", want: true}, - {prefix: "other.txt", want: false}, - {prefix: "/other.txt", want: false}, - {prefix: "/file.txt", want: false}, - {prefix: "/fil", want: false}, - {prefix: "/file.txt2", want: false}, - {prefix: "/.", want: false}, - }, - }, - { - m: File, - long: "./file.txt", - tests: []matcherTest{ - {prefix: "", want: true}, - {prefix: "f", want: true}, - {prefix: "./f", want: true}, - {prefix: "./.", want: false}, - {prefix: "file.", want: true}, - {prefix: "./file.", want: true}, - {prefix: "file.txt", want: true}, - {prefix: "./file.txt", want: true}, - {prefix: "other.txt", want: false}, - {prefix: "/other.txt", want: false}, - {prefix: "/file.txt", want: false}, - {prefix: "/fil", want: false}, - {prefix: "/file.txt2", want: false}, - {prefix: "/.", want: false}, - }, - }, - { - m: File, - long: "/file.txt", - tests: []matcherTest{ - {prefix: "", want: true}, - {prefix: "f", want: false}, - {prefix: "./f", want: false}, - {prefix: "./.", want: false}, - {prefix: "file.", want: false}, - {prefix: "./file.", want: false}, - {prefix: "file.txt", want: false}, - {prefix: "./file.txt", want: false}, - {prefix: "other.txt", want: false}, - {prefix: "/other.txt", want: false}, - {prefix: "/file.txt", want: true}, - {prefix: "/fil", want: true}, - {prefix: "/file.txt2", want: false}, - {prefix: "/.", want: false}, - }, - }, - { - m: File, - long: "./", - tests: []matcherTest{ - {prefix: "", want: true}, - {prefix: ".", want: true}, - {prefix: "./", want: true}, - {prefix: "./.", want: false}, - }, - }, - } - - for _, tt := range tests { - for _, ttt := range tt.tests { - name := fmt.Sprintf("matcher=%T&long='%s'&prefix='%s'", tt.m, tt.long, ttt.prefix) - t.Run(name, func(t *testing.T) { - got := tt.m(tt.long, ttt.prefix) - if got != ttt.want { - t.Errorf("Failed %s: got = %t, want: %t", name, got, ttt.want) - } - }) - } - } -} -- cgit v1.2.3