diff --git a/MANIFEST b/MANIFEST index 7fb5d310..c5122953 100644 --- a/MANIFEST +++ b/MANIFEST @@ -130,6 +130,7 @@ t/compile.t t/data/cat/cat-n-1.txt t/data/sort/ints1.txt t/data/sort/letters1.txt +t/data/sort/three-words.txt t/cat.t t/echo.t t/factor.t diff --git a/t/data/sort/three-words.txt b/t/data/sort/three-words.txt new file mode 100644 index 00000000..07a2a739 --- /dev/null +++ b/t/data/sort/three-words.txt @@ -0,0 +1,8 @@ +the wonderful unicorn +based little mint +the meta protocol +a little love +mooing persistent cat +mooing yodelling dog +row by row +column by pencil diff --git a/t/sort.t b/t/sort.t index ba723b15..42f6efb7 100644 --- a/t/sort.t +++ b/t/sort.t @@ -3,28 +3,62 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 3; sub _lines2re { return join( qq#\r?\n#, @_ ) . qq#\r?\n?#; } +sub test_sort { - my $letters_re = _lines2re(qw/ a b c d e f /); + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($args) = @_; - # TEST - like( scalar(`$^X -Ilib bin/sort t/data/sort/letters1.txt`), - qr#\A$letters_re\z#ms, "letters sort" ); + my $re = _lines2re( @{ $args->{lines} } ); + return like( + scalar(`$^X -Ilib bin/sort @{$args->{flags}} @{$args->{files}}`), + qr#\A$re\z#ms, $args->{blurb} ); } -{ - my $ints_re = _lines2re( 1 .. 100 ); +# TEST +test_sort( + { + blurb => "letters sort", + files => [qw( t/data/sort/letters1.txt )], + flags => [], + lines => [qw/ a b c d e f /], + } +); - # TEST - like( scalar(`$^X -Ilib bin/sort -n t/data/sort/ints1.txt`), - qr#\A$ints_re\z#ms, "integers sort" ); -} +# TEST +test_sort( + { + blurb => "integers sort", + files => [qw( t/data/sort/ints1.txt )], + flags => [qw/ -n /], + lines => [ 1 .. 100 ], + } +); + +# TEST +test_sort( + { + blurb => "multiple -k sort", + files => [qw( t/data/sort/three-words.txt )], + flags => [qw/ -k 2 -k 1 /], + lines => [ split /\n/, <<'EOF'], +column by pencil +row by row +a little love +based little mint +the meta protocol +mooing persistent cat +the wonderful unicorn +mooing yodelling dog +EOF + } +); __END__