File: ext_format.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 (74 lines) | stat: -rw-r--r-- 1,391 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/local/bin/perl -w

use strict ;
use Test ;
use Text::Diff ;
use Algorithm::Diff qw( traverse_sequences ) ;

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

## This tests both that we can overload all 5 methods and that all 5
## methods are called by diff() (and in the right order :)

my $f = "My::Diff::Format" ;
my $diff = diff \@A, \@B, { CONTEXT => 0, STYLE => $f } ;

my @tests = (
sub {
    if ( $diff =~ /(^${f}::.*){8}/sm ) {
        ok 1 ;
    }
    else {
	ok $diff, "8 lines of output" ;
    }
},

sub {
    if ( $diff =~ m{
            file_header.*
	    hunk_header.*
	    hunk.*
	    hunk_footer.*
	    hunk_header.*
	    hunk.*
	    hunk_footer.*
	    file_footer
        }sx
    ) {
        ok 1 ;
    }
    else {
	ok $diff, "proper ordering (see test source)" ;
    }
},

) ;

plan tests => scalar @tests ;

$_->() for @tests ;

package My::Diff::Format ;

use Data::Dumper ;

sub _dump {
    my $prefix = (caller(1))[3] ;
    local $Data::Dumper::Indent = 0 ;
    local $Data::Dumper::Terse  = 1 ;

    join( "",
        map { s/^/$prefix: /mg ; $_ ; } join ", ", map {
	    my $s = ref $_ ? Dumper $_ : $_ ;
	    $s =~ s/([\000-\026])/sprintf "\0x%02x", ord $1/ge ;
	    $s ;
	} @_
    ) . "\n" ;
}

sub file_header { &_dump }
sub hunk_header { &_dump }
sub hunk        { &_dump }
sub hunk_footer { &_dump }
sub file_footer { &_dump }