14 Commits

Author SHA1 Message Date
Igor Murzov
4d76b721f4 testsuite: Set correct COMP_POINT value in test. 2011-11-09 18:14:59 +03:00
Igor Murzov
588facb6b6 testsuite: Add one more test for _get_comp_words_by_ref()
This test exposes bug in __get_cword_at_cursor_by_ref().
2011-11-09 04:54:52 +03:00
Freddy Vulto
fc96a951b7 Fix error "bad array subscript"
Caused by _get_comp_words_by_ref() with cursor at position 0.
Patch by Igor Murzov (Debian: #559953)
2011-05-19 22:40:14 +02:00
Ville Skyttä
41ce815827 testsuite: Add some failing _get_comp_words_by_ref testcases when cursor is before first word. 2011-05-01 17:33:24 +03:00
Ville Skyttä
0448c765ba testsuite: Add test case for Debian: #622383.
The fix is in commit 4ad538ba1a0ccb483899b4eaa70cc604d2b7bf78.
2011-05-01 16:00:07 +03:00
Ville Skyttä
6589a0d61b Drop support for bash < 4.1, clean up no longer needed low hanging cruft. 2011-04-21 12:20:59 +03:00
Freddy Vulto
7cd17ada11 Fix __reassemble_comp_words_by_ref() unquoted pattern removal
Commit 8227e76 was failing on these `chown' tests in bash-4.1:

    FAIL: Check preserve special chars in funky\ user:Debia<TAB>
    FAIL: Check preserve special chars in funky\.user:Debia<TAB>
    FAIL: Check preserve special chars in fu\ nky.user:Debia<TAB>
    FAIL: Check preserve special chars in f\ o\ o\.\bar:Debia<TAB>
    FAIL: Check preserve special chars in foo\_b\ a\.r\ :Debia<TAB>

because a removal pattern is expanded:

    $ a=\\b
    $ w=\\
    $ echo ${a#$w}    # Doesn't work
    \b
    $ echo ${a#"$w"}  # Ok
    b
2011-03-27 22:08:55 +02:00
Freddy Vulto
8227e76e09 Improve __reassemble_comp_words_by_ref() (Alioth #313057)
Prohibit word creation of characters if they're excluded from
$COMP_WORDBREAKS.  For example, with ':' included in $COMP_WORDBREAKS,
'a b:' should split to 'b' and ':'.  With ':' excluded from
$COMP_WORDBREAKS, 'a b:' should split to 'b:', NOT 'b' and ':'.
2011-03-24 00:00:58 +01:00
Freddy Vulto
11da957e45 (testsuite) `match_items()' matches on bash-prompt
Also made `match_items()' more strict about matching
space/newline/prompt after the last item.

Added options to match_items():
- end-newline
- end-prompt
- end-space
and transferred them to other functions.

Function `assert_complete()' now has a `-nospace' option to explicitly
disallow a space after a completion...

Function `assert_bash_list()' now expects a single item to be followed
by a newline.
2010-11-17 23:36:58 +01:00
Freddy Vulto
e8d84b3004 Bugfix __reassemble_comp_words_by_ref
a b:c |<TAB> (with |=cursor) did not return `b:c' as `prev' on bash-4.1
(Alioth #312740)
2010-10-05 21:39:58 +02:00
Freddy Vulto
51b3e20ebc (testsuite) Drop ending block comments
Instead of writing `}; # if', write just `}' as was discussed here:

    http://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg01815.html
2010-06-18 17:21:38 +02:00
Freddy Vulto
a8dd58cfa9 Added _upvars' and _upvar'.
These helper methods aid in passing variables by reference.
2010-06-09 22:37:02 +02:00
Freddy Vulto
bdca37a7bf Improve _get_comp_words_by_ref to return words' and cword'
Usage: _get_comp_words_by_ref [OPTIONS] [VARNAMES]
Available VARNAMES:
    cur         Return cur within varname "cur"
    prev        Return prev within varname "prev"
    words       Return words within varname "words"
    cword       Return cword within varname "cword"

Available OPTIONS:
    -n EXCLUDE  Characters out of $COMP_WORDBREAKS which should NOT be
                considered word breaks. This is useful for things like scp
                where we want to return host:path and not only path, so we
                would pass the colon (:) as -n option in this case.  Bash-3
                doesn't do word splitting, so this ensures we get the same
                word on both bash-3 and bash-4.
    -c VARNAME  Return cur within specified VARNAME
    -p VARNAME  Return prev within specified VARNAME
    -w VARNAME  Return words within specified VARNAME
    -i VARNAME  Return words within specified VARNAME

Example usage:

   $ _get_comp_words_by_ref -n : cur prev
2010-03-14 11:07:13 +01:00
Freddy Vulto
b529cee550 Added _get_comp_words_by_ref()
This solves the following problems:
- now one function call suffices instead of two (_get_cword; _get_pword) if
  subsequent words need to be retrieved.  Also more than two words can be
  retrieved at once, e.g.: _get_comp_words_by_ref cur prev prev2 prev3
  Also this prevents passing of `wordbreakchars' to differ in calls to
  `_get_cword' and `_get_pword', e.g.: _get_comp_words_by_ref -n : cur prev
- passing by reference, no subshell call necessary anymore
- _get_pword now also takes into account the cursor position

Added testsuite proc `assert_no_output()'

Word of caution:

The passing-arguments-by-ref system in bash doesn't work if the new variable is
also declared local.  For example:

    t() {
        local a
        # ...
        eval $1=b
    }
    a=c; t a; echo $a  # Outputs "c", should be "b"
                       # Variable "a" is 'forbidden'

To make name collissions like this less likely to happen, but make the real
function still use readable variables, I've wrapped the `*_by_ref'
functions within an additional layer using variables prefixed with double
underscores (__).  For example:

    _t() {
        # Readable variables can still be used here
        local a
        # ...
        eval $1=b
    }
    t() {
        local __a
        _t __a
        eval $1=\$__a
    }
    a=c; t a; echo $a  # Outputs "b"
                       # Variable "__a" is 'forbidden'

Now only more obfuscated variables (starting with double prefix (__)) are
forbidden to use.
2010-02-07 15:18:58 +01:00