Bash-Completion-Plugin-Test
view release on metacpan or search on metacpan
lib/Bash/Completion/Plugin/Test.pm view on Meta::CPAN
my $plugin = $self->_create_plugin;
$plugin->complete($req);
my @got_completions = $req->candidates;
is_deeply [ sort @got_completions ], [ sort @$expected_completions ],
$name;
}
sub _cursor_character {
return '^';
}
sub _extract_cursor {
my ( $self, $command_line ) = @_;
my $cursor_char = $self->_cursor_character;
my $index = index $command_line, $cursor_char;
if($index == -1) {
croak "Failed to find cursor character in command line";
}
my $replacements = $command_line =~ s/\Q$cursor_char\E//g;
if($replacements > 1) {
croak "More than one cursor character in command line";
}
return ( $command_line, $index );
}
sub _create_request {
my ( $self, $command_line ) = @_;
my $cursor_index;
( $command_line, $cursor_index ) = $self->_extract_cursor($command_line);
local $ENV{'COMP_LINE'} = $command_line;
local $ENV{'COMP_POINT'} = $cursor_index;
return Bash::Completion::Request->new;
}
sub _create_plugin {
my ( $self ) = @_;
my $plugin_class = $self->{'plugin_class'};
return $plugin_class->new;
lib/Bash/Completion/Plugin/Test.pm view on Meta::CPAN
Creates a new tester object. C<%params> is a hash of named parameters;
currently, the only supported one is C<plugin>, which is the name of the
plugin to test, and is required.
=head2 $tester->check_completions($command, \@expected, $name)
Runs the current completion plugin against C<$command>, and verifies
that the results it returns are the same as those in C<@expected>.
The order of the items in C<@expected> does not matter. C<$name> is
an optional name for the test. The carat character '^' must be present
in C<$command>; it is removed and represents the location of the cursor
when completion occurs.
=head1 SEE ALSO
L<Bash::Completion>
=head1 AUTHOR
Rob Hoelz <rob@hoelz.ro>
t/01-basic.t view on Meta::CPAN
plugin => 'Bash::Completion::Plugins::TestPlugin',
);
$tester->check_completions('test-plugin ^',
[qw/foo bar baz/], 'test all completions');
},
{
ok => 1,
name => 'test all completions',
},
'test cursor after blank character',
);
check_test(
sub {
my $tester = Bash::Completion::Plugin::Test->new(
plugin => 'Bash::Completion::Plugins::TestPlugin',
);
$tester->check_completions('test-plugin^',
[qw//], 'test no completions immediately after command');
},
{
ok => 1,
name => 'test no completions immediately after command',
},
'test cursor at end of command',
);
check_test(
sub {
my $tester = Bash::Completion::Plugin::Test->new(
plugin => 'Bash::Completion::Plugins::TestPlugin',
);
$tester->check_completions('test-plugin ^',
[qw/bar baz foo/], 'test all completions');
},
{
ok => 1,
name => 'test all completions',
},
'test cursor after blank character, different completion order',
);
check_test(
sub {
my $tester = Bash::Completion::Plugin::Test->new(
plugin => 'Bash::Completion::Plugins::TestPlugin',
);
$tester->check_completions('test-plugin ^',
[qw/foo baz/]);
t/01-basic.t view on Meta::CPAN
);
$tester->check_completions('test-plugin-nodup ^ bar',
[qw/foo bar baz/]);
},
{
ok => 0,
}
);
# XXX test when the cursor is in the middle of the word
done_testing;
( run in 0.254 second using v1.01-cache-2.11-cpan-4d50c553e7e )