From a870df577ac2e5cfeff291fe3c8710caf3509e4e Mon Sep 17 00:00:00 2001 From: Andy Lester Date: Sat, 30 Nov 2024 21:34:16 -0600 Subject: [PATCH] More tests for regex building --- ack | 6 +++-- t/build_regex.t | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- tags | 6 +++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/ack b/ack index 872a85b..f279ed0 100755 --- a/ack +++ b/ack @@ -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; diff --git a/t/build_regex.t b/t/build_regex.t index c2b40a4..926d7b1 100644 --- a/t/build_regex.t +++ b/t/build_regex.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 4; +use Test::More tests => 12; use App::Ack; @@ -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' + ); } @@ -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; diff --git a/tags b/tags index 4983f9c..905a2e2 100644 --- a/tags +++ b/tags @@ -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 @@ -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 @@ -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 @@ -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