Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • t/completion.t

    rb017b03 r1167bf1  
    88BEGIN {require (dirname($0) . "/mock.pl");};
    99
     10use BarnOwl::Complete::Filter qw(complete_filter_expr);
     11
    1012=head1 DESCRIPTION
    1113
     
    2022    my $after_point = shift;
    2123   
     24    my $ctx = BarnOwl::Completion::Context->new($before_point,
     25                                                $after_point);
     26    is($ctx->line, $before_point . $after_point);
     27    is($ctx->point, length $before_point);
     28
     29    test_ctx($ctx, @_);
     30}
     31
     32sub test_ctx {
     33    local $Test::Builder::Level = $Test::Builder::Level + 1;
     34
     35    my $ctx = shift;
     36
    2237    my $words = shift;
    2338    my $word = shift;
     
    2742    my $word_end   = shift;
    2843
    29     my $ctx = BarnOwl::Completion::Context->new($before_point,
    30                                                 $after_point);
    31 
    32     is($ctx->line, $before_point . $after_point);
    33     is($ctx->point, length $before_point);
    3444    is_deeply($ctx->words, $words);
    3545    if (defined($word)) {
     
    4151}
    4252
     53sub test_shift {
     54    local $Test::Builder::Level = $Test::Builder::Level + 1;
     55
     56    my $before_point = shift;
     57    my $after_point = shift;
     58    my $shift = shift;
     59   
     60    my $ctx = BarnOwl::Completion::Context->new($before_point,
     61                                                $after_point);
     62    $ctx = $ctx->shift_words($shift);
     63
     64    test_ctx($ctx, @_);
     65}
     66
    4367
    4468isa_ok(BarnOwl::Completion::Context->new('Hello, W', 'orld'), 'BarnOwl::Completion::Context');
     
    108132              1, -1, 7, 12);
    109133
     134## Test Context::shift
     135test_shift('lorem ipsum dolor ', 'sit amet', 0,
     136           [qw(lorem ipsum dolor sit amet)],
     137           3, 0, 18, 21);
     138
     139test_shift('lorem ipsum dolor ', 'sit amet', 1,
     140           [qw(ipsum dolor sit amet)],
     141           2, 0, 12, 15);
     142
     143test_shift('lorem ipsum dolor ', 'sit amet', 2,
     144           [qw(dolor sit amet)],
     145           1, 0, 6, 9);
     146
     147test_shift('lorem ipsum dolor ', 'sit amet', 3,
     148           [qw(sit amet)],
     149           0, 0, 0, 3);
     150
     151eval {
     152    my $before_point = 'lorem ipsum dolor';
     153    my $after_point = 'sit amet';
     154    my $shift = 4;
     155
     156    my $ctx = BarnOwl::Completion::Context->new($before_point,
     157                                                $after_point);
     158    $ctx = $ctx->shift_words($shift);
     159};
     160like($@, qr/^Context::shift: Unable to shift /, "Correctly die when shifting away the point");
    110161
    111162## Test common_prefix
     
    163214
    164215test_complete('zwrite -c nelhage ', '',
    165               [qw(-n -C -m -c -i -r -O nelhage asedeno geofft)]);
     216              [qw(-n -C -m -i -r -O nelhage asedeno geofft)]);
    166217
    167218test_complete('zwrite -c nelhage ', '-',
    168               [qw(-n -C -m -c -i -r -O nelhage asedeno geofft)]);
     219              [qw(-n -C -m -i -r -O nelhage asedeno geofft)]);
    169220
    170221test_complete('zwrite -c nelhage -- ', '',
     
    178229                              "-d" => sub {qw(some words for completing)},
    179230                          },
    180                           sub {$_[1]});
     231                          sub {$_[1]},
     232                          repeat_flags => 1);
    181233}
    182234
     
    203255              [qw(2)], \&complete_word);
    204256
     257
     258# Test the filter expression completer
     259test_complete('', '',
     260              [qw[( body class direction false filter hostname instance login not opcode perl realm recipient sender true type]],
     261              \&complete_filter_expr);
     262
     263test_complete('not ', '',
     264              [qw[( body class direction false filter hostname instance login not opcode perl realm recipient sender true type]],
     265              \&complete_filter_expr);
     266
     267test_complete('true ', '',
     268              [qw[and or]],
     269              \&complete_filter_expr);
     270
     271test_complete('( true ', '',
     272              [qw[and or )]],
     273              \&complete_filter_expr);
     274
     275test_complete('( body static and body analysis and not false and class davidben and ( instance python or instance hotd ', '',
     276              [qw[and or )]],
     277              \&complete_filter_expr);
     278
     279test_complete('type ', '',
     280              [qw[admin aim zephyr]],
     281              \&complete_filter_expr);
     282
     283test_complete('direction ', '',
     284              [qw[in out none]],
     285              \&complete_filter_expr);
     286
     287test_complete('login ', '',
     288              [qw[login logout none]],
     289              \&complete_filter_expr);
     290
    2052911;
    206292
Note: See TracChangeset for help on using the changeset viewer.