* Fix some multibyte character completion bugs
- matchLongest now operates on runes instead of bytes so we don't
complete part of a multibyte character.
- Fix some places that mixed string and rune slice indices.
* Fix wrong menu completion for subdirectories
When selecting a menu completion for a file in a subdirectory, the
entire filename would be appended to the command line, even if you had
already typed part of it.
* Escape file completions in menu completion
* Minor refactors and typo fixes
* Fix cmd-menu-complete-back bug
The first use of cmd-menu-complete-back after opening the completion
menu was incorrectly selecting the before-last completion instead of the
last completion.
* Allow completing broken symlinks
Also skip files with stat errors instead of returning.
* Add command to accept current menu selection
This is useful when completing filenames. For example
cmap <c-y> :cmd-menu-accept; cmd-menu-complete
can be used to accept the selected directory completion, then complete
files in the directory.
* Complete command names for map and cmap
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestMatchLongest(t *testing.T) {
|
|
tests := []struct {
|
|
s1 string
|
|
s2 string
|
|
exp string
|
|
}{
|
|
{"", "", ""},
|
|
{"", "foo", ""},
|
|
{"foo", "", ""},
|
|
{"foo", "bar", ""},
|
|
{"foo", "foobar", "foo"},
|
|
{"foo", "barfoo", ""},
|
|
{"foobar", "foobaz", "fooba"},
|
|
{"год", "гол", "го"},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
if got := string(matchLongest([]rune(test.s1), []rune(test.s2))); got != test.exp {
|
|
t.Errorf("at input '%s' and '%s' expected '%s' but got '%s'", test.s1, test.s2, test.exp, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMatchWord(t *testing.T) {
|
|
tests := []struct {
|
|
s string
|
|
words []string
|
|
matches []string
|
|
longest string
|
|
}{
|
|
{"", nil, nil, ""},
|
|
{"", []string{"foo", "bar", "baz"}, []string{"foo", "bar", "baz"}, ""},
|
|
{"fo", []string{"foo", "bar", "baz"}, []string{"foo"}, "foo "},
|
|
{"ba", []string{"foo", "bar", "baz"}, []string{"bar", "baz"}, "ba"},
|
|
{"fo", []string{"bar", "baz"}, nil, "fo"},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
m, l := matchWord(test.s, test.words)
|
|
|
|
if !reflect.DeepEqual(m, test.matches) {
|
|
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.matches, m)
|
|
}
|
|
|
|
if ls := string(l); ls != test.longest {
|
|
t.Errorf("at input '%s' with '%s' expected '%s' but got '%s'", test.s, test.words, test.longest, ls)
|
|
}
|
|
}
|
|
}
|