Changeset 29539 for lang/perl/Data-Model

Show
Ignore:
Timestamp:
02/04/09 22:09:49 (5 years ago)
Author:
yappo
Message:

add multi key test case for lookup/lookup_multi

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Data-Model/trunk/t/lib/Mock/Tests/Basic.pm

    r29533 r29539  
    363363} 
    364364 
     365sub t_14_prepere : Test { 
     366    ok(mock->set( bookmark_user => [qw/ 101 yappo /] )); 
     367    ok(mock->set( bookmark_user => [qw/ 102 osawa /] )); 
     368    ok(mock->set( bookmark_user => [qw/ 103 kazuhiro /] )); 
     369} 
     370 
     371sub t_15_lookup_multikey : Tests { 
     372    eval { mock->lookup( bookmark_user => 'yappo' ) }; 
     373    like $@, qr/The number of key is wrong at /; 
     374 
     375    my $lookup; 
     376    $lookup = mock->lookup( bookmark_user => [qw/ 101 yappo /] ); 
     377    isa_ok $lookup, mock_class."::bookmark_user"; 
     378    is $lookup->bookmark_id, 101, 'id'; 
     379    is $lookup->user_id, 'yappo', 'user_id'; 
     380 
     381    $lookup = mock->lookup( bookmark_user => [qw/ 102 osawa /] ); 
     382    isa_ok $lookup, mock_class."::bookmark_user"; 
     383    is $lookup->bookmark_id, 102, 'id'; 
     384    is $lookup->user_id, 'osawa', 'user_id'; 
     385 
     386    $lookup = mock->lookup( bookmark_user => [qw/ 103 kazuhiro /] ); 
     387    isa_ok $lookup, mock_class."::bookmark_user"; 
     388    is $lookup->bookmark_id, 103, 'id'; 
     389    is $lookup->user_id, 'kazuhiro', 'user_id'; 
     390} 
     391 
     392sub t_16_lookup_multi_multikey : Tests { 
     393    eval { mock->lookup_multi( bookmark_user => 'yappo' ) }; 
     394    like $@, qr/The number of key is wrong at /; 
     395    eval { mock->lookup_multi( bookmark_user => ['yappo'] ) }; 
     396    like $@, qr/The number of key is wrong at /; 
     397 
     398    my($lookup) = mock->lookup_multi( bookmark_user => [ [qw/ 101 yappo /] ]); 
     399    isa_ok $lookup, mock_class."::bookmark_user"; 
     400    is $lookup->bookmark_id, 101, 'id'; 
     401    is $lookup->user_id, 'yappo', 'user_id'; 
     402 
     403    my @lookup = mock->lookup_multi( bookmark_user => [ [qw/ 102 osawa /], [qw/ 103 kazuhiro /] ] ); 
     404    isa_ok $lookup[0], mock_class."::bookmark_user"; 
     405    is $lookup[0]->bookmark_id, 102, 'id'; 
     406    is $lookup[0]->user_id, 'osawa', 'user_id'; 
     407    isa_ok $lookup[1], mock_class."::bookmark_user"; 
     408    is $lookup[1]->bookmark_id, 103, 'id'; 
     409    is $lookup[1]->user_id, 'kazuhiro', 'user_id'; 
     410} 
     411 
    3654121;