4 chdir 't' unless -d 't';
9 use Test::More tests => 8;
10 use vars qw( $Term::Complete::complete $complete );
12 use_ok( 'Term::Complete' );
14 *complete = \$Term::Complete::complete;
16 my $in = tie *STDIN, 'FakeIn', "fro\t";
17 my $out = tie *STDOUT, 'FakeOut';
18 my @words = ( 'frobnitz', 'frobozz', 'frostychocolatemilkshakes' );
20 Complete('', \@words);
21 my $data = get_expected('fro', @words);
23 # there should be an \a after our word
24 like( $$out, qr/fro\a/, 'found bell character' );
26 # now remove the \a -- there should be only one
27 is( $out->scrub(), 1, '(single) bell removed');
29 # 'fro' should match all three words
30 like( $$out, qr/$data/, 'all three words possible' );
33 # should only find 'frobnitz' and 'frobozz'
37 is( $$out, get_expected('frob', 'frobnitz', 'frobozz'), 'expected frob*' );
40 # should only do 'frobozz'
44 is( $$out, get_expected( 'frobo', 'frobozz' ), 'only frobozz possible' );
47 # change the completion character
50 Complete('prompt:', @words);
52 like( $$out, qr/prompt:frobn/, 'prompt is okay' );
54 # now remove the prompt and we should be okay
55 $$out =~ s/prompt://g;
56 is( $$out, get_expected('frobn', 'frobnitz' ), 'works with new $complete' );
58 # easier than matching space characters
61 return join('.', $word, @_, $word, '.');
67 my ($class, $text) = @_;
68 $text .= "$main::complete\025";
69 bless(\$text, $class);
73 my ($self, $text) = @_;
74 $$self = $text . "$main::complete\025";
79 return length $$self ? substr($$self, 0, 1, '') : "\r";
85 bless(\(my $text), $_[0]);
92 # remove the bell character
94 ${ $_[0] } =~ tr/\a//d;
100 ($$self .= join('', @_)) =~ s/\s+/./gm;