Changeset 82a6e8b for t


Ignore:
Timestamp:
Jul 27, 2009, 11:23:57 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7be5d8b
Parents:
b73bcbb
git-author:
Nelson Elhage <nelhage@mit.edu> (07/27/09 22:20:40)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/27/09 23:23:57)
Message:
Add a generic function for completing a command with options.

Implement some minimal tests, too.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • t/completion.t

    r6e48560 r82a6e8b  
    118118is(BarnOwl::Completion::common_prefix(qw(abc abc)), 'abc');
    119119
     120## Test complete_flags
     121
     122use BarnOwl::Completion::Util qw(complete_flags);
     123
     124# dummy complete_zwrite
     125sub complete_zwrite {
     126    my $ctx = shift;
     127    return complete_flags($ctx,
     128                          [qw(-n -C -m)],
     129                          {
     130                              "-c" => sub {qw(nelhage nethack sipb help)},
     131                              "-i" => sub {qw()},
     132                              "-r" => sub {qw(ATHENA.MIT.EDU ZONE.MIT.EDU ANDREW.CMU.EDU)},
     133                              "-O" => sub {qw()},
     134                          },
     135                          sub {qw(nelhage asedeno geofft)});
     136}
     137
     138sub test_complete {
     139    my $before = shift;
     140    my $after = shift;
     141    my $words = shift;
     142   
     143    my $ctx = BarnOwl::Completion::Context->new($before, $after);
     144
     145    local $Test::Builder::Level = $Test::Builder::Level + 1;
     146
     147    my @got = complete_zwrite($ctx);
     148    is_deeply([sort @got], [sort @$words]);
     149}
     150
     151test_complete('zwrite -c ', '', [qw(nelhage nethack sipb help)]);
     152
     153test_complete('zwrite -c nelhage', '', [qw(nelhage nethack sipb help)]);
     154
     155test_complete('zwrite -c nelhage -i ', '', [qw()]);
     156
     157test_complete('zwrite -c nelhage ', '',
     158              [qw(-n -C -m -c -i -r -O nelhage asedeno geofft)]);
     159
     160test_complete('zwrite -c nelhage ', '-',
     161              [qw(-n -C -m -c -i -r -O nelhage asedeno geofft)]);
     162
    1201631;
     164
Note: See TracChangeset for help on using the changeset viewer.