Skip to content

Commit

Permalink
more tests for #get, #delete and #set
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryo Anazawa committed Jul 31, 2013
1 parent ae618c7 commit 4601f5e
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions t/10_basic.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,18 +45,66 @@ subtest 'header fields' => sub {
is $header->delete('Foo'), 'bar'; is $header->delete('Foo'), 'bar';
}; };


subtest '#get' => sub {
my $header = CGI::Header->new(
header => {
foo => 'bar',
bar => 'baz',
},
);

is $header->get('Foo'), 'bar';

is $header->get('Foo', 'Bar'), 'baz',
'get last property in scalar context';

is_deeply(
[ $header->get('Foo', 'Bar') ],
[ 'bar', 'baz' ],
'get multiple props. at once'
);
};

subtest '#set' => sub { subtest '#set' => sub {
my $header = CGI::Header->new; my $header = CGI::Header->new;


throws_ok { $header->set('Foo') } qr{^Odd number of arguments passed}; throws_ok { $header->set('Foo') } qr{^Odd number of arguments passed},
'exception with odd number arguments';

is $header->set( Foo => 'bar' ), 'bar',
'set return single new value in scalar context';

is_deeply(
[ $header->set( oink => 'blah', xxy => 'flop' ) ],
[ 'blah', 'flop' ],
'set returns newly set values in order of keys provided'
);

is_deeply $header->header, {
foo => 'bar',
oink => 'blah',
xxy => 'flop',
};
};

subtest '#delete' => sub {
my $header = CGI::Header->new(
header => {
foo => 'bar',
oink => 'blah',
xxy => 'flop',
},
);

is $header->delete('foo'), 'bar', 'delete returns deleted value';


my @got = $header->set( is_deeply(
Foo => 'bar', [ $header->delete('oink', 'xxy') ],
Bar => 'baz', [ 'blah', 'flop' ],
'delete returns all deleted values in list context'
); );


is_deeply \@got, [qw/bar baz/]; is_deeply $header->header, {};
is_deeply $header->header, { foo => 'bar', bar => 'baz' };
}; };


subtest 'header props.' => sub { subtest 'header props.' => sub {
Expand Down

0 comments on commit 4601f5e

Please sign in to comment.