Add the following packages libalgorithm-diff-perl libspiffy-perl libtext-diff-perl...
[pkg-perl] / deb-src / libtext-diff-perl / libtext-diff-perl-0.35 / t / table.t
1 #!/usr/local/bin/perl -w
2
3 use strict ;
4 use Test ;
5 use Text::Diff ;
6
7 sub t($$$$) {
8     my ( $a, $b, $exp_a, $exp_b ) = @_;
9     my $d = diff \$a, \$b, { STYLE => "Table" };
10     my $re = qr/^\*.*\|\Q$exp_a\E\s*\|\Q$exp_b\E\s*\*$/m;
11
12     ## Older Test.pms don't support ok( $foo, qr// );
13     $d =~ $re
14         ? ok 1
15         : ok "\n" . $d, "a match for " . $re;
16 }
17
18 sub slurp { open SLURP, "<" . shift or die $! ; return join "", <SLURP> }
19
20 my @tests = (
21 sub { t " ",  "\t",  "\\s", "\\t" },
22 sub { t " a", "\ta", " a", "\\ta" },
23 sub { t "a ", "a\t", "a\\s", "a\\t" },
24 sub { t "\t", "\\t", "\\t", "\\\\t" },
25 sub { t "\ta", "\tb", "        a", "        b" },
26 sub { t "-\ta", "-\tb", "-       a", "-       b" },
27 sub { t "\\ta", "\\tb", "\\ta", "\\tb" },
28 ) ;
29
30 plan tests => scalar @tests ;
31
32 $_->() for @tests ;