/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Mon Jun 25 08:16:44 2007 UTC revision 11 by dpavlin, Mon Jun 25 13:13:37 2007 UTC
# Line 1  Line 1 
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    

Legend:
Removed from v.10  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26