#!/usr/bin/perl -w

# Load test the Digest::TransformPath module

use strict;
use lib ();
use UNIVERSAL 'isa';
use File::Spec::Functions ':ALL';
BEGIN {
	$| = 1;
	unless ( $ENV{HARNESS_ACTIVE} ) {
		require FindBin;
		chdir ($FindBin::Bin = $FindBin::Bin); # Avoid a warning
		lib->import( catdir( updir(), updir(), 'modules') );
	}
}





# Does everything load?
use Test::More 'tests' => 25;
use Digest::TransformPath ();





#####################################################################
# ->new

is( Digest::TransformPath->new,        undef, 'Bad ->new returns undef' );
is( Digest::TransformPath->new(undef), undef, 'Bad ->new returns undef' );
is( Digest::TransformPath->new( \"foo" ), undef, 'Bad ->new returns undef' );
is( Digest::TransformPath->new( [ 'foo' ] ), undef, 'Bad ->new returns undef' );
is( Digest::TransformPath->new( { foo => 'bar' } ), undef, 'Bad ->new returns undef' );
is_deeply( Digest::TransformPath->new( 'Foo' ), (bless [ 'Foo' ], 'Digest::TransformPath'), 'Bad ->new returns undef' );





#####################################################################
# ->add

my $Foo = Digest::TransformPath->new('Foo');
isa_ok( $Foo, 'Digest::TransformPath' );
is( $Foo->add, undef, 'Bad ->add fails' );
is( $Foo->add(undef), undef, 'Bad ->add fails' );
is( $Foo->add(['Foo']), undef, 'Bad ->add files' );
is( $Foo->add('Bar'), 1, '->add returns true for legal value' );
is_deeply( $Foo, (bless [ 'Foo', 'Bar' ], 'Digest::TransformPath'),
	'Handles addition correctly' );
is( $Foo->add('This and that'), 1, '->add returns true for legal value' );
is_deeply( $Foo, (bless [ 'Foo', 'Bar', 'This and that' ], 'Digest::TransformPath'),
	'Handles multiple addition correctly' );




#####################################################################
# ->source_id

is( $Foo->source_id, 'Foo', '->source_id returns correct value' );





#####################################################################
# ->digest

is( $Foo->digest(undef), undef, 'Bad ->digest call returns undef' );
is( $Foo->digest([]),    undef, 'Bad ->digest call returns undef' );
is( $Foo->digest(0),     undef, 'Bad ->digest call returns undef' );
is( $Foo->digest(33),    undef, 'Bad ->digest call returns undef' );

is( $Foo->digest,     'ee12781a3ab0d1d1de99d0cb9a82fe21', '->digest returns correct digest' );
is( $Foo->digest(1),  'e',                                '->digest(1) returns correctly' );
is( $Foo->digest(2),  'ee',                               '->digest(2) returns correctly' );
is( $Foo->digest(10), 'ee12781a3a',                       '->digest(10) returns correctly' );
is( $Foo->digest(31), 'ee12781a3ab0d1d1de99d0cb9a82fe2',  '->digest(31) returns correctly' );
is( $Foo->digest(32), 'ee12781a3ab0d1d1de99d0cb9a82fe21', '->digest(32) returns correctly' );

1;
