4 print "1..0 # Skip: not a tty\n" unless -t STDOUT;
5 chdir 't' unless -d 't';
10 use Test::More tests => 8;
11 use vars qw( $Term::Complete::complete $complete );
13 use_ok( 'Term::Complete' );
15 *complete = \$Term::Complete::complete;
17 my $in = tie *STDIN, 'FakeIn', "fro\t";
18 my $out = tie *STDOUT, 'FakeOut';
19 my @words = ( 'frobnitz', 'frobozz', 'frostychocolatemilkshakes' );
21 Complete('', \@words);
22 my $data = get_expected('fro', @words);
24 # there should be an \a after our word
25 like( $$out, qr/fro\a/, 'found bell character' );
27 # now remove the \a -- there should be only one
28 is( $out->scrub(), 1, '(single) bell removed');
30 # 'fro' should match all three words
31 like( $$out, qr/$data/, 'all three words possible' );
34 # should only find 'frobnitz' and 'frobozz'
38 is( $$out, get_expected('frob', 'frobnitz', 'frobozz'), 'expected frob*' );
41 # should only do 'frobozz'
45 is( $$out, get_expected( 'frobo', 'frobozz' ), 'only frobozz possible' );
48 # change the completion character
51 Complete('prompt:', @words);
53 like( $$out, qr/prompt:frobn/, 'prompt is okay' );
55 # now remove the prompt and we should be okay
56 $$out =~ s/prompt://g;
57 is( $$out, get_expected('frobn', 'frobnitz' ), 'works with new $complete' );
59 # easier than matching space characters
62 return join('.', $word, @_, $word, '.');
68 my ($class, $text) = @_;
69 $text .= "$main::complete\025";
70 bless(\$text, $class);
74 my ($self, $text) = @_;
75 $$self = $text . "$main::complete\025";
80 return length $$self ? substr($$self, 0, 1, '') : "\r";
86 bless(\(my $text), $_[0]);
93 # remove the bell character
95 ${ $_[0] } =~ tr/\a//d;
101 ($$self .= join('', @_)) =~ s/\s+/./gm;