Permalink
Browse files

Add -o test from ack1

  • Loading branch information...
1 parent a1d847b commit 29bbaddcbe3c602155666b6419036fbbcaaea4a0 @hoelzro hoelzro committed Mar 7, 2012
Showing with 84 additions and 0 deletions.
  1. +84 −0 t/ack-o.t
View
@@ -0,0 +1,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+ );
+ 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+ -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 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' );
+}

0 comments on commit 29bbadd

Please sign in to comment.