Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions t/data/sort/three-words.txt
Original file line number Diff line number Diff line change
@@ -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
56 changes: 45 additions & 11 deletions t/sort.t
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down