1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#!perl -T
use warnings;
use strict;
use Test::More tests => 24;
use lib 't';
use Util;
prep_environment();
ARG: {
my @expected = line_split( <<'HERE' );
shall have a new birth of freedom -- and that government of the people,
HERE
my @files = qw( t/text/gettysburg.txt );
my @args = qw( free --output=$_ );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Matching line' );
}
ARG_MULTIPLE_FILES: {
# Note the first line is there twice because it matches twice.
my @expected = line_split( <<'HERE' );
or prohibiting the free exercise thereof; or abridging the freedom of
or prohibiting the free exercise thereof; or abridging the freedom of
A well regulated Militia, being necessary to the security of a free State,
Number of free Persons, including those bound to Service for a Term
shall have a new birth of freedom -- and that government of the people,
HERE
my @files = qw( t/text );
my @args = qw( free --sort-files -h --output=$_ );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Matching line' );
}
MATCH: {
my @expected = (
'free'
);
my @files = qw( t/text/gettysburg.txt );
my @args = qw( free --output=$& );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Part of a line matching pattern' );
}
MATCH_MULTIPLE_FILES: {
my @expected = line_split( <<'HERE' );
t/text/bill-of-rights.txt:4:free
t/text/bill-of-rights.txt:4:free
t/text/bill-of-rights.txt:10:free
t/text/constitution.txt:32:free
t/text/gettysburg.txt:23:free
HERE
my @files = qw ( t/text );
my @args = qw( free --sort-files --output=$& );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Part of a line matching pattern' );
}
PREMATCH: {
# No HEREDOC here since we do not want our editor/IDE messing with trailing whitespace.
my @expected = (
'shall have a new birth of '
);
my @files = qw( t/text/gettysburg.txt );
my @args = qw( freedom --output=$` );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Part of a line preceding match' );
}
PREMATCH_MULTIPLE_FILES: {
# No HEREDOC here since we do not want our editor/IDE messing with trailing whitespace.
my @expected = (
'or prohibiting the free exercise thereof; or abridging the ',
'shall have a new birth of '
);
my @files = qw( t/text/);
my @args = qw( freedom -h --sort-files --output=$` );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Part of a line preceding match' );
}
POSTMATCH: {
my @expected = line_split( <<'HERE' );
-- and that government of the people,
HERE
my @files = qw( t/text/gettysburg.txt );
my @args = qw( freedom --output=$' );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Part of a line that follows match' );
}
POSTMATCH_MULTIPLE_FILES: {
my @expected = line_split( <<'HERE' );
of
-- and that government of the people,
HERE
my @files = qw( t/text/ );
my @args = qw( freedom -h --sort-files --output=$' );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Part of a line that follows match' );
}
SUBPATTERN_MATCH: {
my @expected = (
'love-God-Montresor'
);
my @files = qw( t/text/amontillado.txt );
my @args = qw( (love).+(God).+(Montresor) --output=$1-$2-$3 );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Capturing parentheses match' );
}
SUBPATTERN_MATCH_MULTIPLE_FILES: {
my @expected = line_split( <<'HERE' );
the-free-exercise
a-free-State
of-free-Persons
HERE
my @files = qw( t/text/ );
my @args = qw( (\w+)\s(free)\s(\w+) -h --sort-files --output=$1-$2-$3 );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Capturing parentheses match' );
}
INPUT_LINE_NUMBER: {
my @expected = (
'line:15'
);
my @files = qw( t/text/bill-of-rights.txt );
my @args = qw( quartered --output=line:$. );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Line number' );
}
INPUT_LINE_NUMBER_MULTIPLE_FILES: {
my @expected = line_split( <<'HERE' );
t/text/bill-of-rights.txt:4:line:4
t/text/bill-of-rights.txt:4:line:4
t/text/bill-of-rights.txt:10:line:10
t/text/constitution.txt:32:line:32
t/text/gettysburg.txt:23:line:23
HERE
my @files = qw( t/text/ );
my @args = qw( free --sort-files --output=line:$. );
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Line number' );
}
|