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