File: outputs.t

package info (click to toggle)
libtext-diff-perl 0.35-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 108 kB
  • ctags: 35
  • sloc: perl: 949; makefile: 35
file content (49 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/local/bin/perl -w

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

my @A = map "$_\n", qw( 1 2 3 4 ) ;
my @B = map "$_\n", qw( 1 2 3 5 ) ;

sub _d($) { diff \@A, \@B, { OUTPUT => shift } }

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

my $expected  = _d undef ;

my @tests = (
sub { ok $expected =~ tr/\n// },

sub { my $o ; _d sub { $o .= shift } ;  ok $o,             $expected },

sub { my @o ; _d \@o ;                  ok join( "", @o ), $expected },

sub {
    open F, ">output.t.foo" or die $! ;
    _d \*F ;
    close F or die $! ;
    ok slurp "output.t.foo", $expected ;
    unlink "output.t.foo" or warn $! ;
},

sub {
    require IO::File ;
    my $fh = IO::File->new( ">output.t.foo" ) ;
    _d $fh ;
    $fh = undef ;
    ok slurp "output.t.foo", $expected ;
    unlink "output.t.foo" or warn $! ;
},

sub { ok 0 < index( diff( \"\n", \"", { STYLE => "Table" } ), "\\n" ) },

# test for bug reported by Ilya Martynov <ilya@martynov.org> 
sub { ok diff( \"", \"" ), "" },
sub { ok diff( \"A", \"A" ), "" },
) ;

plan tests => scalar @tests ;

$_->() for @tests ;