/[Term-Shelly]/trunk/t/Term-Shelly.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/t/Term-Shelly.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations)
Mon Jun 25 13:13:37 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1220 byte(s)
added tests for complete
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Test::More tests => 23;
7 use Data::Dump qw/dump/;
8 use IO::Scalar;
9 use blib;
10
11 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
72

  ViewVC Help
Powered by ViewVC 1.1.26