1#!/usr/bin/perl -w
2
3# $Id: base.t,v 1.1 2007/08/21 00:46:24 amw Exp $
4
5use strict;
6use Test::More tests => 4;
7
8BEGIN {
9    package My::Test::Format;
10    @My::Test::Format::ISA = ('Text::WordDiff::Base');
11    sub file_header  { $_[0]->filename_a . ' <=> ' .$_[0]->filename_b }
12    sub hunk_header  { ' hunk_header'                                 }
13    sub same_items   { ' same_items ' . shift->foo                    }
14    sub insert_items { ' insert_items'                                }
15    sub delete_items { ' delete_items'                                }
16    sub hunk_footer  { ' hunk_footer'                                 }
17    sub file_footer  { ' ' . $_[0]->mtime_a . ' <=> ' .$_[0]->mtime_b }
18    sub filename_a   { shift->{FILENAME_A}                            }
19    sub filename_b   { shift->{FILENAME_B}                            }
20    sub mtime_a      { shift->{MTIME_A}                               }
21    sub mtime_b      { shift->{MTIME_B}                               }
22    sub foo          { shift->{FOO}                                   }
23}
24
25BEGIN {
26    use_ok 'Text::WordDiff' or die;
27}
28
29ok defined &word_diff, 'word_diff() should be exported';
30
31my $time_a = time;
32my $time_b = $time_a + 1;
33my $localtime_a = localtime $time_a;
34my $localtime_b = localtime $time_b;
35
36my %opts = (
37    STYLE      => 'Text::WordDiff::Base',
38    FILENAME_A => 'foo',
39    FILENAME_B => 'bar',
40    MTIME_A    => $time_a,
41    MTIME_B    => $time_b,
42    FOO        => 'fooo',
43);
44
45my $header = "--- foo\t$localtime_a\n"
46           . "+++ bar\t$localtime_b\n";
47# Test base format class.
48is word_diff(\'this is this', \'this is that', \%opts), $header,
49    'The base format class should output the header only';
50
51# Test formatting methods.
52$opts{STYLE} = 'My::Test::Format';
53my $result = 'foo <=> bar hunk_header same_items fooo hunk_footer hunk_header'
54           . " delete_items insert_items hunk_footer $time_a <=> $time_b";
55
56is word_diff( \'this is this', \'this is that', \%opts), $result,
57    'Each formatting method should be called';
58