4 chdir 't' unless -d 't';
9 use Test::More tests => 8;
10 use vars qw( $Term::Complete::complete $complete );
15 skip('PERL_SKIP_TTY_TEST', 8) if $ENV{PERL_SKIP_TTY_TEST};
18 if ($^O eq 'rhapsody' && -c "/dev/ttyp0") { $TTY = "/dev/ttyp0" }
19 elsif (-c "/dev/tty") { $TTY = "/dev/tty" }
21 open(TTY, $TTY) or die "open $TTY failed: $!";
22 skip("$TTY not a tty", 8) if defined $TTY && ! -t TTY;
24 skip("Can't reliably restore $TTY", 8) if $?;
27 use_ok( 'Term::Complete' );
29 *complete = \$Term::Complete::complete;
31 my $in = tie *STDIN, 'FakeIn', "fro\t";
32 my $out = tie *STDOUT, 'FakeOut';
33 my @words = ( 'frobnitz', 'frobozz', 'frostychocolatemilkshakes' );
35 Complete('', \@words);
36 my $data = get_expected('fro', @words);
38 # there should be an \a after our word
39 like( $$out, qr/fro\a/, 'found bell character' );
41 # now remove the \a -- there should be only one
42 is( $out->scrub(), 1, '(single) bell removed');
44 # 'fro' should match all three words
45 like( $$out, qr/$data/, 'all three words possible' );
48 # should only find 'frobnitz' and 'frobozz'
52 is( $$out, get_expected('frob', 'frobnitz', 'frobozz'), 'expected frob*' );
55 # should only do 'frobozz'
59 is( $$out, get_expected( 'frobo', 'frobozz' ), 'only frobozz possible' );
62 # change the completion character
65 Complete('prompt:', @words);
67 like( $$out, qr/prompt:frobn/, 'prompt is okay' );
69 # now remove the prompt and we should be okay
70 $$out =~ s/prompt://g;
71 is( $$out, get_expected('frobn', 'frobnitz' ), 'works with new $complete' );
74 } # end of SKIP, end of tests
76 # easier than matching space characters
79 return join('.', $word, @_, $word, '.');
85 my ($class, $text) = @_;
86 $text .= "$main::complete\025";
87 bless(\$text, $class);
91 my ($self, $text) = @_;
92 $$self = $text . "$main::complete\025";
97 return length $$self ? substr($$self, 0, 1, '') : "\r";
103 bless(\(my $text), $_[0]);
110 # remove the bell character
112 ${ $_[0] } =~ tr/\a//d;
115 # must shift off self
118 ($$self .= join('', @_)) =~ s/\s+/./gm;