Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more tests for #get, #delete and #set

  • Loading branch information...
commit 4601f5edb13c6fda94c5a30b6f8e6cbee9a4d060 1 parent ae618c7
Ryo Anazawa authored
Showing with 54 additions and 6 deletions.
  1. +54 −6 t/10_basic.t
View
60 t/10_basic.t
@@ -45,18 +45,66 @@ subtest 'header fields' => sub {
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 {
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(
- Foo => 'bar',
- Bar => 'baz',
+ is_deeply(
+ [ $header->delete('oink', 'xxy') ],
+ [ 'blah', 'flop' ],
+ 'delete returns all deleted values in list context'
);
- is_deeply \@got, [qw/bar baz/];
- is_deeply $header->header, { foo => 'bar', bar => 'baz' };
+ is_deeply $header->header, {};
};
subtest 'header props.' => sub {
Please sign in to comment.
Something went wrong with that request. Please try again.