Skip to content

Commit

Permalink
bust out the regex_eq
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 7, 2024
1 parent e56e1f3 commit eb723d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
23 changes: 23 additions & 0 deletions t/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ our @EXPORT = qw(
is_empty_array
is_nonempty_array
regex_eq
first_line_like
build_ack_invocation
adjust_executable
Expand Down Expand Up @@ -1232,4 +1234,25 @@ sub adjust_executable {
}


sub regex_eq {
local $Test::Builder::Level = $Test::Builder::Level + 1;

my $got = shift;
my $exp = shift;
my $msg = shift;

if ( "$]" ge '5.014' ) {
# Passed in expressions are in Perl 5.10 format. If we are running newer
# than that, convert the expected string representations.
for my $re ( $got, $exp ) {
if ( defined($re) ) {
$re =~ s/^\(\?([xism]*)-[xism]*:/(?^$1:/;
}
}
}

return is( $got, $exp, $msg );
}


1;
17 changes: 5 additions & 12 deletions t/build_regex.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use Test::More tests => 12;

use App::Ack;

use lib 't';
use Util;


# Note: All of the expected strings have to be in the format before Perl 5.14.
# The _check() function does the transformation.
Expand Down Expand Up @@ -135,17 +138,7 @@ sub _check {

my ($match, $scan) = App::Ack::build_regex( $str, $opt );

if ( "$]" ge '5.014' ) {
# Passed in expressions are in Perl 5.10 format. If we are running newer
# than that, convert the expected string representations.
for my $re ( $exp_match, $exp_scan ) {
if ( defined($re) ) {
$re =~ s/^\(\?([xism]*)-[xism]*:/(?^$1:/;
}
}
}

is( $match, $exp_match, 'match matches' );
is( $scan, $exp_scan, 'scan matches' );
regex_eq( $match, $exp_match, 'match matches' );
regex_eq( $scan, $exp_scan, 'scan matches' );
};
}

0 comments on commit eb723d1

Please sign in to comment.