1 |
# Before `make install' is performed this script should be runnable with |
#!/usr/bin/perl |
|
# `make test'. After `make install' it should work as `perl Term-Shelly.t' |
|
2 |
|
|
3 |
######################### |
use warnings; |
4 |
|
use strict; |
5 |
|
|
6 |
# change 'tests => 1' to 'tests => last_test_to_print'; |
use Test::More tests => 23; |
7 |
|
use Data::Dump qw/dump/; |
8 |
|
use IO::Scalar; |
9 |
|
use blib; |
10 |
|
|
|
use Test::More tests => 1; |
|
11 |
BEGIN { use_ok('Term::Shelly') }; |
BEGIN { use_ok('Term::Shelly') }; |
12 |
|
|
13 |
######################### |
my $debug = shift @ARGV; |
14 |
|
|
15 |
|
ok( my $sh = Term::Shelly->new, 'new' ); |
16 |
|
isa_ok( $sh, 'Term::Shelly' ); |
17 |
|
|
18 |
|
$sh->{'debug'} = $debug; |
19 |
|
|
20 |
|
my @matches = ( qw/ |
21 |
|
aa |
22 |
|
aba |
23 |
|
abb |
24 |
|
aca |
25 |
|
acb |
26 |
|
acc |
27 |
|
/ ); |
28 |
|
|
29 |
|
my @results; |
30 |
|
|
31 |
|
$sh->{"completion_function"} = sub { |
32 |
|
my ($line, $bword, $pos, $curword) = @_; |
33 |
|
|
34 |
|
diag "line: $line bword: $bword pos: $pos curword: '$curword'"; |
35 |
|
|
36 |
|
@results = grep { /^\Q$curword\E/ } @matches; |
37 |
|
return @results; |
38 |
|
}; |
39 |
|
|
40 |
|
$sh->{"readline_callback"} = sub { |
41 |
|
my ( $line ) = @_; |
42 |
|
|
43 |
|
}; |
44 |
|
|
45 |
|
# redirect STDOUT to STDERR so Test::Harness isn't confused |
46 |
|
*STDOUT = *STDERR; |
47 |
|
|
48 |
|
ok( $sh->out( 'test' ), 'out' ); |
49 |
|
|
50 |
|
ok( $sh->handle_key( chr(13) ), 'handle_key' ); |
51 |
|
|
52 |
|
sub keypress { |
53 |
|
my $key = shift; |
54 |
|
my $expect = shift; |
55 |
|
my @expected_complete = @_; |
56 |
|
|
57 |
|
ok( $sh->handle_key( $key ), "handle_key( $key )" ); |
58 |
|
is_deeply( [ @results ], [ @expected_complete ], 'complete' ) if ( @expected_complete ); |
59 |
|
cmp_ok( $sh->{'input_line'}, 'eq', "$expect " ); |
60 |
|
} |
61 |
|
|
62 |
|
for my $i ( 0 .. $#matches ) { |
63 |
|
keypress( chr(9), $matches[ $i ], @matches ); |
64 |
|
} |
65 |
|
|
66 |
|
diag dump( $sh ) if $debug; |
67 |
|
|
68 |
|
while ( $debug ) { |
69 |
|
$sh->do_one_loop(); |
70 |
|
} |
71 |
|
|
|
# Insert your test code below, the Test::More module is use()ed here so read |
|
|
# its man page ( perldoc Test::More ) for help writing this test script. |
|
72 |
|
|