File: table.t

package info (click to toggle)
libtext-diff-perl 1.45-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 224 kB
  • sloc: perl: 1,059; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 794 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl

use strict ;
use Test ;
use Text::Diff ;

sub t($$$$) {
    my ( $a, $b, $exp_a, $exp_b ) = @_;
    my $d = diff \$a, \$b, { STYLE => "Table" };
    my $re = qr/^\*.*\|\Q$exp_a\E\s*\|\Q$exp_b\E\s*\*$/m;

    ## Older Test.pms don't support ok( $foo, qr// );
    $d =~ $re
        ? ok 1
        : ok "\n" . $d, "a match for " . $re;
}

sub slurp { open SLURP, "<" . shift or die $! ; return join "", <SLURP> }

my @tests = (
sub { t " ",  "\t",  "\\s", "\\t" },
sub { t " a", "\ta", " a", "\\ta" },
sub { t "a ", "a\t", "a\\s", "a\\t" },
sub { t "\t", "\\t", "\\t", "\\\\t" },
sub { t "\ta", "\tb", "        a", "        b" },
sub { t "-\ta", "-\tb", "-       a", "-       b" },
sub { t "\\ta", "\\tb", "\\ta", "\\tb" },
) ;

plan tests => scalar @tests ;

$_->() for @tests ;