Initial implementation of intermediate fuzzy completion

e.g. /u/l/b<tab> may be expanded to /usr/local/bin
This commit is contained in:
ridiculousfish
2015-08-07 13:28:47 -07:00
parent fd96bafbc8
commit b92acd3cf2
3 changed files with 166 additions and 12 deletions

View File

@@ -63,6 +63,7 @@
#include "parse_util.h"
#include "pager.h"
#include "input.h"
#include "wildcard.h"
#include "utf8.h"
#include "env_universal_common.h"
#include "wcstringutil.h"
@@ -1440,14 +1441,30 @@ static void test_expand()
expand_test(L"foo\\$bar", EXPAND_SKIP_VARIABLES, L"foo$bar", 0,
L"Failed to handle dollar sign in variable-skipping expansion");
/*
b
x
bar
baz
xxx
yyy
bax
xxx
.foo
*/
if (system("mkdir -p /tmp/fish_expand_test/")) err(L"mkdir failed");
if (system("mkdir -p /tmp/fish_expand_test/b/")) err(L"mkdir failed");
if (system("mkdir -p /tmp/fish_expand_test/baz/")) err(L"mkdir failed");
if (system("mkdir -p /tmp/fish_expand_test/bax/")) err(L"mkdir failed");
if (system("touch /tmp/fish_expand_test/.foo")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/b/x")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/bar")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/bax/xxx")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/baz/xxx")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/baz/yyy")) err(L"touch failed");
// This is checking that .* does NOT match . and .. (https://github.com/fish-shell/fish-shell/issues/270). But it does have to match literal components (e.g. "./*" has to match the same as "*"
const wchar_t * const wnull = NULL;
@@ -1461,26 +1478,44 @@ static void test_expand()
expand_test(L"/tmp/fish_expand_test/*/xxx", 0,
L"/tmp/fish_expand_test/bax/xxx", L"/tmp/fish_expand_test/baz/xxx", wnull,
L"Glob did the wrong thing");
L"Glob did the wrong thing 1");
expand_test(L"/tmp/fish_expand_test/*z/xxx", 0,
L"/tmp/fish_expand_test/baz/xxx", wnull,
L"Glob did the wrong thing");
L"Glob did the wrong thing 2");
expand_test(L"/tmp/fish_expand_test/**z/xxx", 0,
L"/tmp/fish_expand_test/baz/xxx", wnull,
L"Glob did the wrong thing");
L"Glob did the wrong thing 3");
expand_test(L"/tmp/fish_expand_test/b**", 0,
L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax", L"/tmp/fish_expand_test/bax/xxx", L"/tmp/fish_expand_test/baz", L"/tmp/fish_expand_test/baz/xxx", wnull,
L"Glob did the wrong thing");
L"/tmp/fish_expand_test/b", L"/tmp/fish_expand_test/b/x", L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax", L"/tmp/fish_expand_test/bax/xxx", L"/tmp/fish_expand_test/baz", L"/tmp/fish_expand_test/baz/xxx", L"/tmp/fish_expand_test/baz/yyy", wnull,
L"Glob did the wrong thing 4");
expand_test(L"/tmp/fish_expand_test/BA", EXPAND_FOR_COMPLETIONS,
L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax/", L"/tmp/fish_expand_test/baz/", wnull,
L"Case insensitive test did the wrong thing");
expand_test(L"/tmp/fish_expand_test/BA", EXPAND_FOR_COMPLETIONS,
L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax/", L"/tmp/fish_expand_test/baz/", wnull,
L"Case insensitive test did the wrong thing");
expand_test(L"/tmp/fish_expand_test/b/yyy", EXPAND_FOR_COMPLETIONS,
/* nothing! */ wnull,
L"Wrong fuzzy matching 1");
expand_test(L"/tmp/fish_expand_test/b/x", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH,
L"", wnull, // We just expect the empty string since this is an exact match
L"Wrong fuzzy matching 2");
expand_test(L"/tmp/fish_expand_test/b/xx*", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH,
format_string(L"/tmp/fish_expand_test/bax/xx%lc", (wint_t)ANY_STRING).c_str(), format_string(L"/tmp/fish_expand_test/baz/xx%lc", (wint_t)ANY_STRING).c_str(), wnull,
L"Wrong fuzzy matching 3");
expand_test(L"/tmp/fish_expand_test/b/yyy", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH,
L"/tmp/fish_expand_test/baz/yyy", wnull,
L"Wrong fuzzy matching 4");
if (! expand_test(L"/tmp/fish_expand_test/.*", 0, L"/tmp/fish_expand_test/.foo", 0))
{
err(L"Expansion not correctly handling dotfiles");
@@ -1489,7 +1524,30 @@ static void test_expand()
{
err(L"Expansion not correctly handling literal path components in dotfiles");
}
char saved_wd[PATH_MAX] = {};
if (NULL == getcwd(saved_wd, sizeof saved_wd))
{
err(L"getcwd failed");
return;
}
if (chdir("/tmp/fish_expand_test"))
{
err(L"chdir failed");
return;
}
expand_test(L"b/xx", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH,
L"bax/xxx", L"baz/xxx", wnull,
L"Wrong fuzzy matching 5");
if (chdir(saved_wd))
{
err(L"chdir failed");
}
if (system("rm -Rf /tmp/fish_expand_test")) err(L"rm failed");
}