cf5ca92ca97888b0ecfc199d18060dba16e4fc97
[platform/upstream/coreutils.git] / tests / tac / Test.pm
1 package Test;
2 require 5.002;
3 use strict;
4
5 my @tv = (
6 # test name, options, input, expected output, expected return code
7 #
8 ['basic-0', '', "", "", 0],
9 ['basic-a', '', "a", "a\n", 0],
10 ['basic-b', '', "\n", "\n", 0],
11 ['basic-c', '', "a\n", "a\n", 0],
12 ['basic-d', '', "a\nb", "b\na\n", 0],
13 ['basic-e', '', "a\nb\n", "b\na\n", 0],
14 ['basic-f', '', "1234567\n8\n", "8\n1234567\n", 0],
15 ['basic-g', '', "12345678\n9\n", "9\n12345678\n", 0],
16 ['basic-h', '', "123456\n8\n", "8\n123456\n", 0],
17 ['basic-i', '', "12345\n8\n", "8\n12345\n", 0],
18 ['basic-j', '', "1234\n8\n", "8\n1234\n", 0],
19 ['basic-k', '', "123\n8\n", "8\n123\n", 0],
20
21 ['b2-e', '', "a\nb", "b\na\n", 0],
22 ['b2-f', '', "1234567\n8", "8\n1234567\n", 0],
23 ['b2-g', '', "12345678\n9", "9\n12345678\n", 0],
24 ['b2-h', '', "123456\n8", "8\n123456\n", 0],
25 ['b2-i', '', "12345\n8", "8\n12345\n", 0],
26 ['b2-j', '', "1234\n8", "8\n1234\n", 0],
27 ['b2-k', '', "123\n8", "8\n123\n", 0],
28
29 ['opt-b', '-b', "\na\nb\nc", "\nc\nb\na", 0],
30 ['opt-s', '-s:', "a:b:c:", "c:b:a:", 0],
31 ['opt-sb', '-s : -b', ":a:b:c", ":c:b:a", 0],
32 ['opt-r',     "-r -s '\\._+'", "1._2.__3.___4._", "4._3.___2.__1._", 0],
33
34 ['opt-r2',    "-r -s '\\._+'", "a.___b.__1._2.__3.___4._",
35                                "4._3.___2.__1._b.__a.___", 0],
36
37 # This gave incorrect output (.___4._2.__3._1) with tac-1.22.
38 ['opt-br', "-b -r -s '\\._+'", "._1._2.__3.___4", ".___4.__3._2._1", 0],
39
40 ['opt-br2', "-b -r -s '\\._+'", ".__x.___y.____z._1._2.__3.___4",
41                                 ".___4.__3._2._1.____z.___y.__x", 0],
42 );
43
44 sub test_vector
45 {
46   my $t;
47   foreach $t (@tv)
48     {
49       my ($test_name, $flags, $in, $exp, $ret) = @$t;
50
51       $Test::input_via{$test_name} = {REDIR => 0, FILE => 0, PIPE => 0}
52     }
53
54   # Temporarily turn off losing tests.
55   # These tests lose because tac_file isn't yet up to snuff with tac_mem.
56   foreach $t (qw (basic-a basic-d b2-e b2-f b2-g b2-h b2-i b2-j b2-k))
57     {
58       # $Test::input_via{$t} = {REDIR => 0, PIPE => 0};
59       $Test::input_via{$t} = {};
60     }
61
62   return @tv;
63 }
64
65 1;