source: t/completion.t @ 13614e7

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 13614e7 was 13614e7, checked in by Nelson Elhage <nelhage@mit.edu>, 15 years ago
Context.pm: Return the boundaries of the current word. We need this in order to be able to replace it when completing.
  • Property mode set to 100644
File size: 2.7 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 $word_start = shift;
27    my $word_end   = shift;
28
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);
34    is_deeply($ctx->words, $words);
35    if (defined($word)) {
36        is($ctx->word, $word, "Correct current word.");
37        is($ctx->word_point, $word_point, "Correct point within word.");
38        is($ctx->word_start, $word_start, "Correct start of word");
39        is($ctx->word_end,   $word_end, "Correct end of word");
40    }
41}
42
43
44new_ok('BarnOwl::Completion::Context' => ['Hello, W', 'orld']);
45
46no warnings 'qw';
47test_tokenize('Hello, W', 'orld',
48              [qw(Hello, World)], 1, 1, 7, 12);
49
50test_tokenize('Hello, World', '',
51              [qw(Hello, World)], 1, 5, 7, 12);
52
53test_tokenize('', '',
54              [qw()], 0, 0, 0, 0);
55
56test_tokenize('Hello', 'World',
57              [qw(HelloWorld)], 0, 5, 0, 10);
58
59test_tokenize('lorem ipsum dolor ', 'sit amet',
60              [qw(lorem ipsum dolor sit amet)],
61              3, 0, 18, 21);
62
63test_tokenize(q{error "ls -l failed"}, q{},
64              ['error', 'ls -l failed'],
65              1, 12, 6, 20);
66
67test_tokenize(q{"a long"' word'}, q{},
68              ['a long word']);
69
70test_tokenize(q{"'"}, q{}, [q{'}], 0, 1, 0, 3);
71
72test_tokenize(q{"Hello, }, q{World"},
73              [q{Hello, World}],
74              0, 7, 0, 14);
75
76test_tokenize(q{But 'Hello, }, q{World'},
77              ['But', q{Hello, World}],
78              1, 7, 4, 18);
79
80test_tokenize(q{But "Hello, }, q{World"''''''""},
81              ['But', q{Hello, World}],
82              1, 7, 4, 26);
83
84test_tokenize(q{}, q{''Hello},
85              ['Hello'],
86              0, 0, 0, 7);
87
88test_tokenize(q{"Hello, }, q{World},
89              [q{Hello, World}],
90              0, 7, 0, 13);
91
92test_tokenize(q{Hello    }, q{World},
93              [qw{Hello World}],
94              1, 0, 9, 14);
95
96test_tokenize(q{Hello '' ""}, q{ World},
97              ["Hello", '', '', 'World'],
98              2, 0, 9, 11);
99
100# It's not entirely clear what we should do here. Make a test for the
101# current behavior, so we'll notice if it changes.
102test_tokenize(q{Hello }, q{ World},
103              [qw(Hello World)],
104              1, -1, 7, 12);
105
1061;
Note: See TracBrowser for help on using the repository browser.