[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 2cd91420d2e9a4ce571cbe4e4a90e512653be151

Freddy Vulto fvulto at gmail.com
Sun Feb 7 14:23:28 UTC 2010


The following commit has been merged in the master branch:
commit 2cd91420d2e9a4ce571cbe4e4a90e512653be151
Merge: c72e20b42fe113b5496c3424598dbc5e41e1e644 b529cee550fa20678ecd7c92ed575f3342db1d49
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Sun Feb 7 15:21:44 2010 +0100

    Merge branch 'fvu'

diff --combined test/lib/library.exp
index 3de310b,a7a376e..0092f3f
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@@ -79,18 -79,22 +79,22 @@@ proc assert_bash_type {command} 
  # @result boolean  True if successful, False if not
  proc assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} {
      if {$test == ""} {set test "$cmd should show expected output"}
-     send "$cmd\r"
-     expect -ex "$cmd\r\n"
- 
-     if {[match_items $expected $test $prompt $size]} {
-         expect {
-             -re $prompt { pass "$test" }
-             -re eof { unresolved "eof" }
-         }; # expect
+     if {[llength $expected] == 0} {
+         assert_no_output $cmd $test $prompt
      } else {
-         fail "$test"
-     }; # if
- }; # assert_bash_list()
+         send "$cmd\r"
+         expect -ex "$cmd\r\n"
+ 
+         if {[match_items $expected $test $prompt $size]} {
+             expect {
+                 -re $prompt { pass "$test" }
+                 -re eof { unresolved "eof" }
+             }
+         } else {
+             fail "$test"
+         }
+     }
+ }
  
  
  proc assert_bash_list_dir {expected cmd dir {test ""} {prompt /@} {size 20}} {
@@@ -451,6 -455,26 +455,26 @@@ proc assert_no_complete {{cmd} {test ""
  }; # assert_no_complete()
  
  
+ # Check that no output is generated on a certain command.
+ # @param string $cmd  The command to attempt to complete.
+ # @param string $test  Optional parameter with test name.
+ # @param string $prompt  (optional) Bash prompt.  Default is "/@"
+ proc assert_no_output {{cmd} {test ""} {prompt /@}} {
+     if {[string length $test] == 0} {
+         set test "$cmd shouldn't generate output"
+     }
+ 
+     send "$cmd\r"
+     expect -ex "$cmd"
+ 
+     expect {
+         -re "^\r\n$prompt$" { pass "$test" }
+         default { fail "$test" }
+         timeout { fail "$test" }
+     }
+ }
+ 
+ 
  # Source/run file with additional tests if completion for the specified command
  # is installed in bash.
  # @param string $command  Command to check completion availability for.
@@@ -721,73 -745,6 +745,73 @@@ proc split_words_bash {line} 
  }; # split_words_bash()
  
  
 +# Given a list of items this proc finds a (part, full) pair so that when
 +# completing from $part $full will be the only option.
 +#
 +# Arguments:
 +#       list        The list of full completions.
 +#       partName    Output parameter for the partial string.
 +#       fullName    Output parameter for the full string, member of item.
 +#
 +# Results:
 +#       1, or 0 if no suitable result was found.
 +proc find_unique_completion_pair {{list} {partName} {fullName}} {
 +    upvar $partName part
 +    upvar $fullName full
 +    set bestscore 0
 +    set list [lsort $list]
 +    set n [llength $list]
 +    for {set i 0} {$i < $n} {incr i} {
 +        set cur [lindex $list $i]
 +        set curlen [string length $cur]
 +
 +        set prev [lindex $list [expr {$i - 1}]]
 +        set next [lindex $list [expr {$i + 1}]]
 +        set diffprev [expr {$prev == ""}]
 +        set diffnext [expr {$next == ""}]
 +
 +        # Analyse each item of the list and look for the minimum length of the
 +        # partial prefix which is distinct from both $next and $prev. The list
 +        # is sorted so the prefix will be unique in the entire list.
 +        #
 +        # In the worst case we analyse every character in the list 3 times.
 +        # That's actually very fast, sorting could take more.
 +        for {set j 0} {$j < $curlen} {incr j} {
 +            set curchar [string index $cur $j]
 +            if {!$diffprev && [string index $prev $j] != $curchar} {
 +                set diffprev 1
 +            }
 +            if {!$diffnext && [string index $next $j] != $curchar} {
 +                set diffnext 1
 +            }
 +            if {$diffnext && $diffprev} {
 +                break
 +            }
 +        }
 +
 +        # At the end of the loop $j is the index of last character of
 +        # the unique partial prefix. The length is one plus that.
 +        set parlen [expr {$j + 1}]
 +        if {$parlen >= $curlen} {
 +            continue
 +        }
 +
 +        # Try to find the most "readable pair"; look for a long pair where
 +        # $part is about half of $full.
 +        if {$parlen < $curlen / 2} {
 +            set parlen [expr {$curlen / 2}]
 +        }
 +        set score [expr {$curlen - $parlen}]
 +        if {$score > $bestscore} {
 +            set bestscore $score
 +            set part [string range $cur 0 [expr {$parlen - 1}]]
 +            set full $cur
 +        }
 +    }
 +    return [expr {$bestscore != 0}]
 +}
 +
 +
  # Start bash running as test environment.
  proc start_bash {} {
      global TESTDIR TOOL_EXECUTABLE spawn_id

-- 
bash-completion



More information about the Bash-completion-commits mailing list