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
|
#!perl
use warnings;
use strict;
use Test::More tests => 6;
use File::Next ();
use lib 't';
use Util;
prep_environment();
NO_O: {
my @files = qw( t/text/boy-named-sue.txt );
my @args = qw( the\\s+\\S+ --text );
my @expected = split( /\n/, <<'EOF' );
But the meanest thing that he ever did
But I made me a vow to the moon and stars
That I'd search the honky-tonks and bars
Sat the dirty, mangy dog that named me Sue.
Well, I hit him hard right between the eyes
And we crashed through the wall and into the street
Kicking and a-gouging in the mud and the blood and the beer.
And it's the name that helped to make you strong."
And I know you hate me, and you got the right
For the gravel in ya gut and the spit in ya eye
Cause I'm the son-of-a-bitch that named you Sue."
EOF
s/^\s+// for @expected;
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Find all the things without -o' );
}
WITH_O: {
my @files = qw( t/text/boy-named-sue.txt );
my @args = qw( the\\s+\\S+ --text -o );
my @expected = split( /\n/, <<'EOF' );
the meanest
the moon
the honky-tonks
the dirty,
the eyes
the wall
the street
the mud
the blood
the beer.
the name
the right
the gravel
the spit
the son-of-a-bitch
EOF
s/^\s+// for @expected;
my @results = run_ack( @args, @files );
lists_match( \@results, \@expected, 'Find all the things with -o' );
}
# give a output function and find match in multiple files (so print filenames, just like grep -o)
WITH_OUTPUT: {
my @files = qw( t/text/ );
my @args = qw/ --output=x$1x -a question(\\S+) /;
my @target_file = (
File::Next::reslash( 't/text/science-of-myth.txt' ),
File::Next::reslash( 't/text/shut-up-be-happy.txt' ),
);
my @expected = (
"$target_file[0]:1:xedx",
"$target_file[1]:15:xs.x",
"$target_file[1]:21:x.x",
);
my @results = run_ack( @args, @files );
sets_match( \@results, \@expected, 'Find all the things with --output function' );
}
|