1use Test::Base tests => 23; 2 3BEGIN { use_ok('Text::Diff3', ':factory') }; 4 5my $a = ['1 line', '2 line', '3 line', q{}, q{}]; 6my $t; 7 8# If you test another Factory change this 9my $Factory = 'Text::Diff3::Factory'; 10 11can_ok($Factory, 'new'); 12my $factory = $Factory->new; 13 14can_ok($factory, 'create_text'); 15 16my $text = $factory->create_text($a); 17my $text2 = $factory->create_text(join "\n", @$a, q{}); 18is_deeply($text, $text2, 'constructor can accept array ref or string'); 19 20can_ok($text, 'first_index'); 21can_ok($text, 'last_index'); 22can_ok($text, 'at'); 23can_ok($text, 'eq_at'); 24can_ok($text, 'as_string_at'); 25can_ok($text, 'size'); 26can_ok($text, 'range'); 27 28ok(! defined($text->at($text->first_index - 1)), 29 '$text->at($text->first_index - 1) == undef'); 30 31ok(! defined($text->at($text->first_index - 1)), 32 '$text->at($text->last_index + 1) == undef'); 33 34my $size = $text->last_index - $text->first_index + 1; 35ok($size == @$a, 'size() returns collectly'); 36ok($size == $text->size, 'size == last - first + 1'); 37 38my @range = $text->range; 39ok($size == @range, 'size == @range'); 40ok($text->first_index == $range[0], 'first_index == range[0]'); 41ok($text->last_index == $range[-1], 'last_index == range[-1]'); 42 43$t = [map { $text->at($_) } @range]; 44is_deeply($a, $t, 'at() returns collect lines'); 45 46$t = 0; 47for (@range) { 48 ++$t if $text->eq_at($_, $text->at($_)); 49} 50ok($t == @range, 'eq_at($_, at($_))'); 51 52$t = $text->first_index - 1; 53ok($text->eq_at($t, undef), 'undef eq undef'); 54ok(! $text->eq_at($t, $text->at($t + 1)), 'undef ne first_line'); 55ok(! $text->eq_at($t + 1, undef), 'first_line ne undef'); 56