[8eac1a5] | 1 | #!/usr/bin/env perl |
---|
| 2 | use strict; |
---|
| 3 | use warnings; |
---|
| 4 | |
---|
| 5 | use Test::More qw(no_plan); |
---|
| 6 | |
---|
| 7 | use File::Basename; |
---|
| 8 | BEGIN {require (dirname($0) . "/mock.pl");}; |
---|
| 9 | |
---|
| 10 | =head1 DESCRIPTION |
---|
| 11 | |
---|
| 12 | Basic tests for tab-completion functionality. |
---|
| 13 | |
---|
| 14 | =cut |
---|
| 15 | |
---|
| 16 | sub 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 | |
---|
| 39 | new_ok('BarnOwl::Completion::Context' => ['Hello, W', 'orld']); |
---|
| 40 | |
---|
| 41 | no warnings 'qw'; |
---|
| 42 | test_tokenize('Hello, W', 'orld', |
---|
| 43 | [qw(Hello, World)], 1, 1); |
---|
| 44 | |
---|
| 45 | test_tokenize('Hello, World', '', |
---|
| 46 | [qw(Hello, World)], 1, 5); |
---|
| 47 | |
---|
| 48 | test_tokenize('', '', |
---|
| 49 | [qw()], 0, 0); |
---|
| 50 | |
---|
| 51 | test_tokenize('Hello', 'World', |
---|
| 52 | [qw(HelloWorld)], 0, 5); |
---|
| 53 | |
---|
| 54 | test_tokenize('lorem ipsum dolor ', 'sit amet', |
---|
| 55 | [qw(lorem ipsum dolor sit amet)], 3, 0); |
---|
| 56 | |
---|
| 57 | test_tokenize(q{error "ls -l failed"}, q{}, |
---|
| 58 | ['error', 'ls -l failed'], 1, 12); |
---|
| 59 | |
---|
| 60 | test_tokenize(q{"a long"' word'}, q{}, |
---|
| 61 | ['a long word']); |
---|
| 62 | |
---|
| 63 | test_tokenize(q{"'"}, q{}, [q{'}]); |
---|
| 64 | |
---|
| 65 | test_tokenize(q{"Hello, }, q{World"}, |
---|
| 66 | [q{Hello, World}], 0, 7); |
---|
| 67 | |
---|
| 68 | test_tokenize(q{But 'Hello, }, q{World'}, |
---|
| 69 | ['But', q{Hello, World}], 1, 7); |
---|
| 70 | |
---|
| 71 | test_tokenize(q{But "Hello, }, q{World"''''''""}, |
---|
| 72 | ['But', q{Hello, World}], 1, 7); |
---|
| 73 | |
---|
| 74 | test_tokenize(q{}, q{''Hello}, |
---|
| 75 | ['Hello'], 0, 0); |
---|
| 76 | |
---|
| 77 | test_tokenize(q{"Hello, }, q{World}, |
---|
| 78 | [q{Hello, World}], 0, 7); |
---|
| 79 | |
---|
| 80 | test_tokenize(q{Hello }, q{World}, |
---|
| 81 | [qw{Hello World}], 1, 0); |
---|
| 82 | |
---|
| 83 | test_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. |
---|
| 88 | test_tokenize(q{Hello }, q{ World}, |
---|
| 89 | [qw(Hello World)], 1, -1); |
---|
| 90 | |
---|
| 91 | 1; |
---|