source: t/completion.t @ 8eac1a5

release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8eac1a5 was 8eac1a5, checked in by Nelson Elhage <nelhage@mit.edu>, 12 years ago
Implement and test BarnOwl::Completion::Context. This is the class responsible for tokenizing the command-line for tab-completion.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1#!/usr/bin/env perl
2use strict;
3use warnings;
4
5use Test::More qw(no_plan);
6
7use File::Basename;
8BEGIN {require (dirname($0) . "/mock.pl");};
9
10=head1 DESCRIPTION
11
12Basic tests for tab-completion functionality.
13
14=cut
15
16sub test_tokenize {
17    local $Test::Builder::Level = $Test::Builder::Level + 1;
18
19    my $before_point = shift;
20    my $after_point = shift;
21   
22    my $words = shift;
23    my $word = shift;
24    my $word_point = shift;
25
26    my $ctx = BarnOwl::Completion::Context->new($before_point,
27                                                $after_point);
28
29    is($ctx->line, $before_point . $after_point);
30    is($ctx->point, length $before_point);
31    is_deeply($ctx->words, $words);
32    if (defined($word)) {
33        is($ctx->word, $word, "Correct current word.");
34        is($ctx->word_point, $word_point, "Correct point within word.");
35    }
36}
37
38
39new_ok('BarnOwl::Completion::Context' => ['Hello, W', 'orld']);
40
41no warnings 'qw';
42test_tokenize('Hello, W', 'orld',
43              [qw(Hello, World)], 1, 1);
44
45test_tokenize('Hello, World', '',
46              [qw(Hello, World)], 1, 5);
47
48test_tokenize('', '',
49              [qw()], 0, 0);
50
51test_tokenize('Hello', 'World',
52              [qw(HelloWorld)], 0, 5);
53
54test_tokenize('lorem ipsum dolor ', 'sit amet',
55              [qw(lorem ipsum dolor sit amet)], 3, 0);
56
57test_tokenize(q{error "ls -l failed"}, q{},
58              ['error', 'ls -l failed'], 1, 12);
59
60test_tokenize(q{"a long"' word'}, q{},
61              ['a long word']);
62
63test_tokenize(q{"'"}, q{}, [q{'}]);
64
65test_tokenize(q{"Hello, }, q{World"},
66              [q{Hello, World}], 0, 7);
67
68test_tokenize(q{But 'Hello, }, q{World'},
69              ['But', q{Hello, World}], 1, 7);
70
71test_tokenize(q{But "Hello, }, q{World"''''''""},
72              ['But', q{Hello, World}], 1, 7);
73
74test_tokenize(q{}, q{''Hello},
75              ['Hello'], 0, 0);
76
77test_tokenize(q{"Hello, }, q{World},
78              [q{Hello, World}], 0, 7);
79
80test_tokenize(q{Hello    }, q{World},
81              [qw{Hello World}], 1, 0);
82
83test_tokenize(q{Hello '' ""}, q{ World},
84              ["Hello", '', '', 'World'], 2, 0);
85
86# It's not entirely clear what we should do here. Make a test for the
87# current behavior, so we'll notice if it changes.
88test_tokenize(q{Hello }, q{ World},
89              [qw(Hello World)], 1, -1);
90
911;
Note: See TracBrowser for help on using the repository browser.