DAIA

 view release on metacpan or  search on metacpan

t/20entities.t  view on Meta::CPAN

    }

    $e = &$shortcut( $hashref );
    is_deeply( $e->struct, $hashref, 'struct' );

    my $copy = &$shortcut( $e );
    $e->content("xxx");
    is_deeply( $copy, $hashref, 'copy constructor' );

    #my $copy = &$shortcut( $e );
    #is_deeply( $copy, $hashref, 'copy constructor ignores hidden' );

    $e->content(undef);
    is( $e->content, '', 'undef is empty string' );

    $e->content(undef);
    $e->id(undef);
    $e->href(undef);
    is_deeply( $e->struct, { content => '' }, 'remove_..' );

    $e = $class->new( $content );
    is_deeply( $e->struct, { content => $content }, 'content only (short)' );

    $e = &$shortcut( content => $content );
    is_deeply( $e->struct, { content => $content }, 'content only (param)' );

    # invalid values
    eval { $e->id('~123'); };
    ok ( $@, 'valid URI needed as id' );
    eval { $e->href('htp://x'); };
    ok ( $@, 'valid URL needed as href' );
}

# TODO: test adding entities (raw DAIA::Entity should not be allowed)

my $item = item( department => "foo" );
my $item2 = item();

done_testing;

__END__

$item2->department( content => "foo" );
print $item->json . "\n" . $item2->json . "\n";
is_deeply( $item2, $item );

my $dep = item->department;
my @args = ( [ department("foo") ], [ "foo" ], [ content => "foo" ] );

foreach my $args (@args) {
    my $item2 = item();
    diag( join(" | ", @{$args} ) );
    $item2->department( @{$args} );
    is_deeply( $item2->struct, $item->struct );    
}

__END__
    # TODO

    # Check that strings are encoded in UTF-8
    my %unicode = (
        "\xE4" => "\xC3\xA4"
    );
    foreach my $s (keys %unicode) {
        $e = $class->new( content => $s );
        is ( $e->json, '{"string":"'. $unicode{$s} . '"}', "UTF-8" );
    }



( run in 1.506 second using v1.01-cache-2.11-cpan-437f7b0c052 )