Skip to content

Commit

Permalink
More tests for regex building
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 1, 2024
1 parent 340d704 commit a870df5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
6 changes: 4 additions & 2 deletions ack
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,11 @@ MAIN: {
close $App::Ack::fh;

App::Ack::exit_from_ack( $nmatches );
}
} # End of MAIN


exit 0;

# End of MAIN

sub file_loop_fg {
my $files = shift;
Expand Down
66 changes: 65 additions & 1 deletion t/build_regex.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use warnings;
use strict;

use Test::More tests => 4;
use Test::More tests => 12;

use App::Ack;

Expand All @@ -16,6 +16,31 @@ PLAIN: {
'(?m-xis:foo)',
'Nuthin fancy'
);
_check(
'foo-bar',
{},
'(?-xism:foo-bar)',
'(?m-xis:foo-bar)',
'Not just a plain word'
);
}


SMARTCASE: {
_check(
'foo',
{ S => 1 },
'(?-xism:(?i)foo)',
'(?m-xis:(?i)foo)',
'Smartcase on a lowercase word'
);
_check(
'Foo',
{ S => 1 },
'(?-xism:Foo)',
'(?m-xis:Foo)',
'Smartcase on a mixed-case word'
);
}


Expand Down Expand Up @@ -48,6 +73,45 @@ DASH_i: {
}


DASH_w: {
_check(
'wookie',
{ w => 1 },
'(?-xism:\b(?:wookie)\b)',
'(?m-xis:wookie)',
'Simple -w'
);
_check(
'wookie-boogie',
{ w => 1 },
'(?-xism:(?:^|\b|\s)\K(?:wookie-boogie)(?=\s|\b|$))',
'(?m-xis:wookie-boogie)',
'Not just a single word'
);
_check(
'blah.*',
{ w => 1 },
'(?-xism:(?:^|\b|\s)\K(?:blah.*)(?=\s|\b|$))',
'(?m-xis:blah.*)',
'-w on something ending with metacharacters'
);
_check(
'[abc]thing',
{ w => 1 },
'(?-xism:(?:^|\b|\s)\K(?:[abc]thing)(?=\s|\b|$))',
'(?m-xis:[abc]thing)',
'-w on something beginning with a range'
);
_check(
'[abc]thing.+?',
{ w => 1 },
'(?-xism:(?:^|\b|\s)\K(?:[abc]thing.+?)(?=\s|\b|$))',
'(?m-xis:[abc]thing.+?)',
'-w on something beginning with a range and ending with metacharacters'
);
}


exit 0;


Expand Down
6 changes: 6 additions & 0 deletions tags
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ DASH_LC t/ack-c.t /^DASH_LC: {$/;" l
DASH_LV t/ack-l.t /^DASH_LV: {$/;" l
DASH_NOIGNORE_DIR t/ack-ignore-dir.t /^DASH_NOIGNORE_DIR: {$/;" l
DASH_NOIGNORE_DIR_MULTIPLE_TIMES t/ack-ignore-dir.t /^DASH_NOIGNORE_DIR_MULTIPLE_TIMES: {$/;" l
DASH_Q t/build_regex.t /^DASH_Q: {$/;" l
DASH_V t/ack-1.t /^DASH_V: {$/;" l
DASH_i t/build_regex.t /^DASH_i: {$/;" l
DASH_w t/build_regex.t /^DASH_w: {$/;" l
DEFAULT_DIR_EXCLUSIONS t/ack-f.t /^DEFAULT_DIR_EXCLUSIONS: {$/;" l
DOLLAR_1 t/ack-output.t /^DOLLAR_1: {$/;" l
DOLLAR_UNDERSCORE t/ack-output.t /^DOLLAR_UNDERSCORE: {$/;" l
Expand Down Expand Up @@ -179,6 +182,7 @@ PAGER_WITH_OPTS t/ack-pager.t /^PAGER_WITH_OPTS: {$/;" l
PIPE_INTO_ACK t/from-stdin.t /^PIPE_INTO_ACK: {$/;" l
PIPE_INTO_DASH_C t/from-stdin.t /^PIPE_INTO_DASH_C: {$/;" l
PIPE_INTO_DASH_I t/from-stdin.t /^PIPE_INTO_DASH_I: {$/;" l
PLAIN t/build_regex.t /^PLAIN: {$/;" l
POSTMATCH t/ack-output.t /^POSTMATCH: {$/;" l
POSTMATCH_MULTIPLE_FILES t/ack-output.t /^POSTMATCH_MULTIPLE_FILES: {$/;" l
PREMATCH t/ack-output.t /^PREMATCH: {$/;" l
Expand All @@ -192,6 +196,7 @@ SINGLE_FILE_COUNT t/ack-c.t /^SINGLE_FILE_COUNT: {$/;" l
SINGLE_TEXT_MATCH t/ack-1.t /^SINGLE_TEXT_MATCH: {$/;" l
SKIP t/ack-passthru.t /^SKIP: {$/;" l
SKIP t/file-permission.t /^SKIP: {$/;" l
SMARTCASE t/build_regex.t /^SMARTCASE: {$/;" l
SMART_CASE t/longopts.t /^SMART_CASE: {$/;" l
SPECIFYING_A_BAK_FILE t/command-line-files.t /^SPECIFYING_A_BAK_FILE: {$/;" l
STANDARD_GROUPING t/ack-group.t /^STANDARD_GROUPING: {$/;" l
Expand Down Expand Up @@ -224,6 +229,7 @@ WITH_SWITCHES_MULTIPLE_FILES t/basic.t /^WITH_SWITCHES_MULTIPLE_FILES: {$/;" l
WITH_SWITCHES_ONE_FILE t/ack-h.t /^WITH_SWITCHES_ONE_FILE: {$/;" l
WITH_SWITCHES_ONE_FILE t/basic.t /^WITH_SWITCHES_ONE_FILE: {$/;" l
_big_split t/lowercase.t /^sub _big_split {$/;" s
_check t/build_regex.t /^sub _check {$/;" s
_check_command_for_taintedness t/Util.pm /^sub _check_command_for_taintedness {$/;" s
_check_for_ackrc lib/App/Ack/ConfigFinder.pm /^sub _check_for_ackrc {$/;" s
_check_for_mutex_options lib/App/Ack/ConfigLoader.pm /^sub _check_for_mutex_options {$/;" s
Expand Down

0 comments on commit a870df5

Please sign in to comment.