##  ReDIF::ParserCore first test script:
##



BEGIN {print "1..7\n";}
END {print "not ok 1\n" unless $loaded;}

use ReDIF::Record;

$loaded = 1;

print "ok 1\n";

{
    my $template = ReDIF::Record -> new( -type => 'ReDIF-Person 1.0' );

    print "ok 2\n";
    
    $template -> add_property( "title", "The Paper" );
    $template -> add_property( "handle", "RePEc:wop:aarhec:94-01" );
    $template -> open_structured_property( "author", "person cluster" );

    use pretty_print;
    pretty_print( $template );

    $template -> add_property( "name", "Bob Dylan" );
    $template -> close_structured_property( );
    $template -> add_property( "abstract", "very good paper" );


    my $t_hash = $template -> as_hash();
    
    if( sprintf ($t_hash) !~ /=HASH/ ) {
	print "ref ($t_hash) = " , ref $t_hash, "\n";
	print "not ";
    }
    print "ok 3\n";

    if( $t_hash -> {title} -> [0] ne 'The Paper' ) {
	print "not ";
    }	
    print "ok 4\n";
    
    if( $t_hash -> {handle} -> [0] ne 'RePEc:wop:aarhec:94-01' ) {
	print "not ";
    }	
    print "ok 5\n";

    if( not defined ( $t_hash -> {author} -> [0] ) ) {
 	print "undefined `author[0]'!\n";
	print "not ";
    } elsif( $t_hash -> {author} -> [0] -> {name} -> [0] ne 'Bob Dylan' ) {
	use pretty_print qw( &pretty_print );
	pretty_print( $t_hash );
	print "not ";
    }	
    print "ok 6\n";
    
    if( $t_hash -> {abstract} -> [0] ne 'very good paper' ) {
	use pretty_print qw( &pretty_print );
	pretty_print( $t_hash );
	print "not ";
    }	
    print "ok 7\n";
    
    
}



