diff options
author | 2014-08-15 18:14:36 -0700 | |
---|---|---|
committer | 2014-08-15 18:14:36 -0700 | |
commit | 06400b83b188156f31ed92216ec27122d29f88cd (patch) | |
tree | 2f9cec409aba50449638c8d4361b4dafe530f3ec /fish_tests.cpp | |
parent | fe68d30be97853865b24ad5f5998d3e50769f860 (diff) |
Support for command wrapping ("aliases")
Add the --wraps option to 'complete' and 'function'. This allows a
command to (recursively) inherit the completions of a wrapped command.
Fixes #393.
When evaluating a completion, we inspect the entire "wrap chain" for a
command, i.e. we follow the sequence of wrapping until we either hit a
loop (which we silently ignore) or the end of the chain. We then
evaluate completions as if the wrapping command were substituted with
the wrapped command. Currently this only works for commands, i.e.
'complete --command gco --wraps git\ checkout' won't work (that would
seem to encroaching on abbreviations anyways). It might be useful to
show an error message for that case.
The commandline builtin reflects the commandline with the wrapped
command substituted in, so e.g. git completions (which inspect the
command line) will just work. This sort of command line munging is
also performed by 'complete -C' so it's not totally without precedent.
'alias will also now mark its generated function as wrapping the
'target.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r-- | fish_tests.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp index 7cc5fb9a..bdf12af1 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -166,6 +166,21 @@ static void err(const wchar_t *blah, ...) wprintf(L"\n"); } +// Joins a wcstring_list_t via commas +static wcstring comma_join(const wcstring_list_t &lst) +{ + wcstring result; + for (size_t i=0; i < lst.size(); i++) + { + if (i > 0) + { + result.push_back(L','); + } + result.append(lst.at(i)); + } + return result; +} + #define do_test(e) do { if (! (e)) err(L"Test failed on line %lu: %s", __LINE__, #e); } while (0) /* Test sane escapes */ @@ -1924,6 +1939,18 @@ static void test_complete(void) do_test(completions.empty()); complete_set_variable_names(NULL); + + /* Test wraps */ + do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1"); + complete_add_wrapper(L"wrapper1", L"wrapper2"); + do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1,wrapper2"); + complete_add_wrapper(L"wrapper2", L"wrapper3"); + do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1,wrapper2,wrapper3"); + complete_add_wrapper(L"wrapper3", L"wrapper1"); //loop! + do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1,wrapper2,wrapper3"); + complete_remove_wrapper(L"wrapper1", L"wrapper2"); + do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1"); + do_test(comma_join(complete_get_wrap_chain(L"wrapper2")) == L"wrapper2,wrapper3,wrapper1"); } static void test_1_completion(wcstring line, const wcstring &completion, complete_flags_t flags, bool append_only, wcstring expected, long source_line) |