4 chdir 't' unless -d 't';
9 use Test::More tests => 8;
10 use vars qw( $Term::Complete::complete $complete );
13 skip('PERL_SKIP_TTY_TEST', 8) if $ENV{PERL_SKIP_TTY_TEST};
16 if ($^O eq 'rhapsody' && -c "/dev/ttyp0") { $TTY = "/dev/ttyp0" }
17 elsif (-c "/dev/tty") { $TTY = "/dev/tty" }
19 open(TTY, $TTY) or die "open $TTY failed: $!";
20 skip("$TTY not a tty", 8) if defined $TTY && ! -t TTY;
23 use_ok( 'Term::Complete' );
25 *complete = \$Term::Complete::complete;
27 my $in = tie *STDIN, 'FakeIn', "fro\t";
28 my $out = tie *STDOUT, 'FakeOut';
29 my @words = ( 'frobnitz', 'frobozz', 'frostychocolatemilkshakes' );
31 Complete('', \@words);
32 my $data = get_expected('fro', @words);
34 # there should be an \a after our word
35 like( $$out, qr/fro\a/, 'found bell character' );
37 # now remove the \a -- there should be only one
38 is( $out->scrub(), 1, '(single) bell removed');
40 # 'fro' should match all three words
41 like( $$out, qr/$data/, 'all three words possible' );
44 # should only find 'frobnitz' and 'frobozz'
48 is( $$out, get_expected('frob', 'frobnitz', 'frobozz'), 'expected frob*' );
51 # should only do 'frobozz'
55 is( $$out, get_expected( 'frobo', 'frobozz' ), 'only frobozz possible' );
58 # change the completion character
61 Complete('prompt:', @words);
63 like( $$out, qr/prompt:frobn/, 'prompt is okay' );
65 # now remove the prompt and we should be okay
66 $$out =~ s/prompt://g;
67 is( $$out, get_expected('frobn', 'frobnitz' ), 'works with new $complete' );
69 # easier than matching space characters
72 return join('.', $word, @_, $word, '.');
78 my ($class, $text) = @_;
79 $text .= "$main::complete\025";
80 bless(\$text, $class);
84 my ($self, $text) = @_;
85 $$self = $text . "$main::complete\025";
90 return length $$self ? substr($$self, 0, 1, '') : "\r";
96 bless(\(my $text), $_[0]);
103 # remove the bell character
105 ${ $_[0] } =~ tr/\a//d;
108 # must shift off self
111 ($$self .= join('', @_)) =~ s/\s+/./gm;
114 } # end of SKIP, end of tests