Skip to content

Commit

Permalink
Starting on unit tests for build_regex
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 1, 2024
1 parent 316de3b commit 340d704
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ t/anchored.t
t/bad-ackrc-opt.t
t/basic.t
t/boolean.t
t/build_regex.t
t/command-line-files.t
t/config-backwards-compat.t
t/config-finder.t
Expand Down
73 changes: 73 additions & 0 deletions t/build_regex.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!perl

use warnings;
use strict;

use Test::More tests => 4;

use App::Ack;


PLAIN: {
_check(
'foo',
{},
'(?-xism:foo)',
'(?m-xis:foo)',
'Nuthin fancy'
);
}


DASH_Q: {
_check(
'foo',
{ Q => 1 },
'(?-xism:foo)',
'(?m-xis:foo)',
'Nothing for -Q to do'
);
_check(
'thing^ and ($foo)',
{ Q => 1 },
'(?-xism:thing\^\ and\ \(\$foo\))',
undef, # No scan regex when there are anchors
'-Q has things to escape'
);
}


DASH_i: {
_check(
'NeXT',
{ i => 1 },
'(?-xism:(?i)NeXT)',
'(?m-xis:(?i)NeXT)',
'Simple -i'
);
}


exit 0;


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

my $str = shift;
my $opt = shift;
my $exp_match = shift;
my $exp_scan = shift;
my $msg = shift or die 'Must provide a message';

return subtest $msg => sub () {
$opt = { %{$opt} };

$opt->{$_} //= [] for qw( and or not );

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

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

0 comments on commit 340d704

Please sign in to comment.