From 05a640b0277502c7d6846548873ce1cfe3e9ade4 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 9 Dec 2016 12:14:14 -0800 Subject: [PATCH] Increase test coverage and improve completion commenting --- src/complete.cpp | 5 +++++ tests/test6.in | 10 ++++++++++ tests/test6.out | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/src/complete.cpp b/src/complete.cpp index aecf346e6..a56493063 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -920,6 +920,8 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop } } else if (popt[0] == L'-') { // Set to true if we found a matching old-style switch. + // Here we are testing the previous argument, + // to see how we should complete the current argument bool old_style_match = false; // If we are using old style long options, check for them first. @@ -943,6 +945,8 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop const complete_entry_opt_t *o = &*oiter; // Gnu-style options with _optional_ arguments must be specified as a single // token, so that it can be differed from a regular argument. + // Here we are testing the previous argument for a GNU-style match, + // to see how we should complete the current argument if (o->type == option_type_double_long && !(o->result_mode & NO_COMMON)) continue; @@ -960,6 +964,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop continue; } + // Now we try to complete an option itself for (option_list_t::const_iterator oiter = options.begin(); oiter != options.end(); ++oiter) { const complete_entry_opt_t *o = &*oiter; diff --git a/tests/test6.in b/tests/test6.in index 193cee314..dffe5e1a9 100644 --- a/tests/test6.in +++ b/tests/test6.in @@ -56,6 +56,16 @@ complete -c TestDoubleDash -l TestDoubleDashOption complete -C'TestDoubleDash -' | sort echo "Expect no output:" (complete -C'TestDoubleDash -- -' | sort) +# fish seems to have always handled "exclusive" options strangely +# It seems to treat them the same as "old-style" (single-dash) long options +echo "Testing exclusive options" +complete -c TestExclusive -x -s Q +complete -c TestExclusive -x -s W +complete -c TestExclusive -s A +echo "Expect -A -Q -W:" (complete -C'TestExclusive -' | sort | string join ' ') +echo "Expect -AQ -AW:" (complete -C'TestExclusive -A' | sort | string join ' ') +echo "Expect no output 1:" (complete -C'TestExclusive -Q') +echo "Expect no output 2:" (complete -C'TestExclusive -W') # Test that directory completions work correctly if begin; rm -rf test6.tmp.dir; and mkdir test6.tmp.dir; end diff --git a/tests/test6.out b/tests/test6.out index a7f04732c..81c2684a7 100644 --- a/tests/test6.out +++ b/tests/test6.out @@ -33,6 +33,11 @@ CCCC: Test that -- suppresses option completions --TestDoubleDashOption Expect no output: +Testing exclusive options +Expect -A -Q -W: -A -Q -W +Expect -AQ -AW: -AQ -AW +Expect no output 1: +Expect no output 2: implicit cd complete works no implicit cd complete after 'command' PATH does not cause incorrect implicit cd