8
unless ( $ENV{DISPLAY} or $^O eq 'MSWin32' ) {
9
plan skip_all => 'Needs DISPLAY';
23
######################################################################
24
# Basic tests for the core matches method
27
my ( $start, $end, @matches ) = Padre::Search->matches(
33
is_deeply( \@matches, [], 'no match' );
37
my (@matches) = Padre::Search->matches(
43
is_deeply( \@matches, [ 1, 2, [ 1, 2 ] ], 'one match' );
47
my (@matches) = Padre::Search->matches(
53
is_deeply( \@matches, [ 1, 2, [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 'three matches' );
57
my (@matches) = Padre::Search->matches(
63
is_deeply( \@matches, [ 3, 4, [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 'three matches' );
67
my (@matches) = Padre::Search->matches(
73
is_deeply( \@matches, [ 5, 6, [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 'three matches' );
77
my (@matches) = Padre::Search->matches(
83
is_deeply( \@matches, [ 1, 2, [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 'three matches, wrapping' );
87
my (@matches) = Padre::Search->matches(
94
is_deeply( \@matches, [ 3, 4, [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 'three matches backwards' );
98
my (@matches) = Padre::Search->matches(
105
is_deeply( \@matches, [ 5, 6, [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 'three matches backwards wrapping' );
109
my (@matches) = Padre::Search->matches(
115
is_deeply( \@matches, [ 3, 5, [ 1, 3 ], [ 3, 5 ] ], '2 matches' );
119
my (@matches) = Padre::Search->matches(
121
regex => qr/(b(.?))/,
126
is_deeply( \@matches, [ 5, 6, [ 1, 3 ], [ 3, 5 ], [ 5, 6 ] ], 'three matches bw, wrap' );
130
my $str = qq( perl ("שלום"); perl );
131
my (@matches) = Padre::Search->matches(
138
# TODO are these really correct numbers?
139
is_deeply( \@matches, [ 1, 5, [ 1, 5 ], [ 28, 32 ] ], 'two matches with unicode' );
140
is( substr( $str, 1, 4 ), 'perl' );
145
my (@matches) = Padre::Search->matches(
151
is_deeply( \@matches, [ 1, 7, [ 1, 7 ] ], 'one match with unicode regex' );
152
is( substr( $str, 1, 4 ), 'üss' );
159
######################################################################
160
# Searching within a selection
162
my $text = <<'END_TEXT';
165
All your base are belong to us.
169
my $search = new_ok( 'Padre::Search', [ find_term => 'are' ] );
170
my ( $first_char, $last_char, @all ) = $search->matches(
177
ok( $first_char, 'calling matches with proper parameters should work' );
178
is( $first_char, 6, 'found first entry at position 6' );
179
is( $last_char, 9, 'found first entry ending at position 9' );
180
is( substr( $text, $first_char, $last_char - $first_char ),
182
'position is correct',
191
'matches returns a correct structure',
196
my $search = new_ok( 'Padre::Search', [ find_term => 'are' ] );
199
my ( $first_char, $last_char, @all ) = $search->matches(
200
text => substr( $text, $sel_begin, $sel_end - $sel_begin ),
203
to => $sel_end - $sel_begin,
205
ok( $first_char, 'calling matches with proper parameters should work' );
206
is( $first_char, 1, 'found relative entry at position 1' );
207
is( $last_char, 4, 'found relative entry ending at position 4' );
208
is( substr( $text, $first_char + $sel_begin, $last_char - $first_char ),
210
'relative position is correct',
218
'matches returns a correct relative structure (within selection)',