Browse files

remove obsolete tests

  • Loading branch information...
1 parent 3eb34ba commit e7e2e9ce1d4405b356b6cbfebb58507fe201d91c Ryo Anazawa committed Sep 25, 2012
View
2 lib/CGI/Header.pm
@@ -201,7 +201,7 @@ sub is_empty { !shift->SCALAR }
sub field_names {
my $self = shift;
my $this = refaddr $self;
- my %header = %{ $header_of{$this} }; # copy
+ my %header = %{ $header_of{$this} }; # shallow copy
my @fields;
View
66 t/20_basic.t → t/12_basic.t
@@ -3,16 +3,16 @@ use warnings;
use CGI::Header;
use CGI::Cookie;
use CGI::Util 'expires';
-use Test::More tests => 17;
+use Test::More tests => 19;
use Test::Warn;
use Test::Exception;
my $class = 'CGI::Header';
can_ok $class, qw(
- new clone clear delete exists get set is_empty each flatten
- date status
- DESTROY
+ new clone clear delete exists get set is_empty
+ header field_names each flatten DESTROY
+ p3p_tags expires nph attachment date status
);
subtest 'new()' => sub {
@@ -72,14 +72,14 @@ subtest 'delete()' => sub {
};
subtest 'each()' => sub {
- my $expected = qr{^Must provide a code reference to each\(\)};
- throws_ok { $header->each } $expected;
-
- %header = (
+ my $header = CGI::Header->new(
-status => '304 Not Modified',
-content_length => 12345,
);
+ my $expected = qr{^Must provide a code reference to each\(\)};
+ throws_ok { $header->each } $expected;
+
my @got;
$header->each(sub {
my ( $field, $value ) = @_;
@@ -152,6 +152,56 @@ subtest 'clone()' => sub {
is_deeply $clone->header, $orig->header;
};
+subtest 'nph()' => sub {
+ %header = ();
+
+ $header->nph( 1 );
+ ok $header->nph;
+ ok $header{-nph} == 1;
+
+ $header->nph( 0 );
+ ok !$header->nph;
+ ok $header{-nph} == 0;
+
+ %header = ( -date => 'Sat, 07 Jul 2012 05:05:09 GMT' );
+ $header->nph( 1 );
+ is_deeply \%header, { -nph => 1 }, '-date should be deleted';
+};
+
+subtest 'field_names()' => sub {
+ %header = ( -type => q{} );
+ is_deeply [ $header->field_names ], [], 'should return null array';
+
+ %header = (
+ -nph => 1,
+ -status => 1,
+ -target => 1,
+ -p3p => 1,
+ -cookie => 1,
+ -expires => 1,
+ -attachment => 1,
+ -foo_bar => 1,
+ -foo => q{},
+ -bar => undef,
+ );
+
+ my @got = $header->field_names;
+
+ my @expected = qw(
+ Status
+ Window-Target
+ P3P
+ Set-Cookie
+ Expires
+ Date
+ Content-Disposition
+ Foo-bar
+ Content-Type
+ );
+
+ is_deeply \@got, \@expected;
+};
+
subtest 'DESTROY()' => sub {
my $h = $class->new;
$h->DESTROY;
View
118 t/12_entity.t
@@ -1,118 +0,0 @@
-use strict;
-use warnings;
-use CGI::Header;
-use Test::More tests => 16;
-
-my $class = 'CGI::Header';
-
-can_ok $class, qw(
- TIEHASH FETCH STORE DELETE EXISTS CLEAR SCALAR DESTROY
- header field_names
- p3p_tags expires nph attachment
- _normalize _denormalize
-);
-
-subtest 'TIEHASH()' => sub {
- my %header = ();
- my $header = $class->TIEHASH( \%header );
- is $header->header, \%header;
- is_deeply $header->header, {};
-
- %header = ( -foo => 'bar' );
- $header = $class->TIEHASH( \%header );
- is $header->header, \%header;
- is_deeply $header->header, { -foo => 'bar' };
-
- $header = $class->TIEHASH;
- is_deeply $header->header, {};
-};
-
-my %adaptee;
-my $adapter = tie my %adapter, $class, \%adaptee;
-
-# SCALAR
-%adaptee = ();
-ok %adapter;
-%adaptee = ( -type => q{} );
-ok !%adapter;
-
-# CLEAR
-%adaptee = ();
-%adapter = ();
-is_deeply \%adaptee, { -type => q{} };
-
-# EXISTS
-%adaptee = ( -foo => 'bar', -bar => q{} );
-ok exists $adapter{Foo};
-ok !exists $adapter{Bar};
-ok !exists $adapter{Baz};
-
-# DELETE
-%adaptee = ( -foo => 'bar', -bar => 'baz' );
-is delete $adapter{Foo}, 'bar';
-is_deeply \%adaptee, { -bar => 'baz' };
-
-# FETCH
-%adaptee = ( -foo => 'bar' );
-is $adapter{Foo}, 'bar';
-is $adapter{Bar}, undef;
-
-# STORE
-%adaptee = ();
-$adapter{Foo} = 'bar';
-is_deeply \%adaptee, { -foo => 'bar' };
-
-subtest 'nph()' => sub {
- %adaptee = ();
-
- $adapter->nph( 1 );
- ok $adapter->nph;
- ok $adaptee{-nph} == 1;
-
- $adapter->nph( 0 );
- ok !$adapter->nph;
- ok $adaptee{-nph} == 0;
-
- %adaptee = ( -date => 'Sat, 07 Jul 2012 05:05:09 GMT' );
- $adapter->nph( 1 );
- is_deeply \%adaptee, { -nph => 1 }, '-date should be deleted';
-};
-
-subtest 'field_names()' => sub {
- %adaptee = ( -type => q{} );
- is_deeply [ $adapter->field_names ], [], 'should return null array';
-
- %adaptee = (
- -nph => 1,
- -status => 1,
- -target => 1,
- -p3p => 1,
- -cookie => 1,
- -expires => 1,
- -attachment => 1,
- -foo_bar => 1,
- -foo => q{},
- -bar => undef,
- );
-
- my @got = $adapter->field_names;
-
- my @expected = qw(
- Status
- Window-Target
- P3P
- Set-Cookie
- Expires
- Date
- Content-Disposition
- Foo-bar
- Content-Type
- );
-
- is_deeply \@got, \@expected;
-};
-
-subtest 'DESTROY()' => sub {
- $adapter->DESTROY;
- ok !$adapter->header;
-};
View
59 t/13_tie.t
@@ -0,0 +1,59 @@
+use strict;
+use warnings;
+use CGI::Header;
+use Test::More tests => 19;
+
+my $class = 'CGI::Header';
+
+my %alias = (
+ TIEHASH => 'new',
+ FETCH => 'get',
+ STORE => 'set',
+ DELETE => 'delete',
+ EXISTS => 'exists',
+ CLEAR => 'clear',
+);
+
+can_ok $class, ( keys %alias, 'SCALAR' );
+
+while ( my ($got, $expected) = each %alias ) {
+ is $class->can($got), $class->can($expected);
+}
+
+my %adaptee;
+tie my %adapter, $class, \%adaptee;
+
+isa_ok tied %adapter, $class;
+
+# SCALAR
+%adaptee = ();
+ok %adapter;
+%adaptee = ( -type => q{} );
+ok !%adapter;
+
+# CLEAR
+%adaptee = ();
+%adapter = ();
+is_deeply \%adaptee, { -type => q{} };
+
+# EXISTS
+%adaptee = ( -foo => 'bar', -bar => q{} );
+ok exists $adapter{Foo};
+ok !exists $adapter{Bar};
+ok !exists $adapter{Baz};
+
+# DELETE
+%adaptee = ( -foo => 'bar', -bar => 'baz' );
+is delete $adapter{Foo}, 'bar';
+is_deeply \%adaptee, { -bar => 'baz' };
+
+# FETCH
+%adaptee = ( -foo => 'bar' );
+is $adapter{Foo}, 'bar';
+is $adapter{Bar}, undef;
+
+# STORE
+%adaptee = ();
+$adapter{Foo} = 'bar';
+is_deeply \%adaptee, { -foo => 'bar' };
+
View
48 t/13_content_type.t → t/20_content_type.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
use CGI::Header;
-use Test::More tests => 28;
+use Test::More tests => 27;
my %adaptee;
my $adapter = tie my %adapter, 'CGI::Header', \%adaptee;
@@ -69,25 +69,6 @@ is_deeply \%adaptee, {
-charset => q{},
};
-SKIP: {
- skip 'obsolete', 2;
-
- %adaptee = ();
- $adapter{Content_Type} = 'text/html; charSet=utf-8';
- is_deeply \%adaptee, {
- -type => 'text/html',
- -charset => 'utf-8',
- };
-
- %adaptee = ();
- $adapter{Content_Type} = 'text/html; charSet="CHARSET"; Foo="CHARSET"';
- is_deeply \%adaptee, {
- -type => 'text/html; foo=CHARSET',
- -charset => 'CHARSET',
- };
-}
-
-
%adaptee = ( -type => undef );
is $adapter{Content_Type}, 'text/html; charset=ISO-8859-1';
ok exists $adapter{Content_Type};
@@ -103,3 +84,30 @@ is_deeply \%adaptee, { -type => q{} };
# feature
%adaptee = ( -type => 'text/plain; charSet=utf-8' );
is $adapter{Content_Type}, 'text/plain; charSet=utf-8; charset=ISO-8859-1';
+
+subtest 'content_type()' => sub {
+ %adaptee = ();
+ is $adapter->content_type, 'text/html';
+ my @got = $adapter->content_type;
+ my @expected = ( 'text/html', 'charset=ISO-8859-1' );
+ is_deeply \@got, \@expected;
+
+ %adaptee = ( -type => 'text/plain; charset=EUC-JP; Foo=1' );
+ is $adapter->content_type, 'text/plain';
+ @got = $adapter->content_type;
+ @expected = ( 'text/plain', 'charset=EUC-JP; Foo=1' );
+ is_deeply \@got, \@expected;
+
+ %adaptee = ();
+ $adapter->content_type( 'text/plain; charset=EUC-JP' );
+ is_deeply \%adaptee, {
+ -type => 'text/plain; charset=EUC-JP',
+ -charset => q{},
+ };
+
+ %adaptee = ( -type => q{} );
+ is $adapter->content_type, q{};
+
+ %adaptee = ( -type => ' TEXT / HTML ' );
+ is $adapter->content_type, 'text/html';
+};
View
34 t/21_content_type.t
@@ -1,34 +0,0 @@
-use strict;
-use warnings;
-use CGI::Header;
-use Test::More tests => 1;
-
-my %adaptee;
-my $adapter = CGI::Header->new( \%adaptee );
-
-subtest 'content_type()' => sub {
- %adaptee = ();
- is $adapter->content_type, 'text/html';
- my @got = $adapter->content_type;
- my @expected = ( 'text/html', 'charset=ISO-8859-1' );
- is_deeply \@got, \@expected;
-
- %adaptee = ( -type => 'text/plain; charset=EUC-JP; Foo=1' );
- is $adapter->content_type, 'text/plain';
- @got = $adapter->content_type;
- @expected = ( 'text/plain', 'charset=EUC-JP; Foo=1' );
- is_deeply \@got, \@expected;
-
- %adaptee = ();
- $adapter->content_type( 'text/plain; charset=EUC-JP' );
- is_deeply \%adaptee, {
- -type => 'text/plain; charset=EUC-JP',
- -charset => q{},
- };
-
- %adaptee = ( -type => q{} );
- is $adapter->content_type, q{};
-
- %adaptee = ( -type => ' TEXT / HTML ' );
- is $adapter->content_type, 'text/html';
-};
View
29 t/14_date.t → t/21_date.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use CGI::Header;
use HTTP::Date;
-use Test::More tests => 3;
+use Test::More tests => 5;
use Test::Warn;
my %adaptee;
@@ -39,3 +39,30 @@ subtest 'Expires' => sub {
warning_is { $adapter{Expires} = '+3M' }
"Can't assign to '-expires' directly, use accessors instead";
};
+
+subtest 'date()' => sub {
+ %adaptee = ();
+ is $adapter->date, undef;
+ my $now = 1341637509;
+ $adapter->date( $now );
+ is $adapter->date, $now;
+ is $adaptee{-date}, 'Sat, 07 Jul 2012 05:05:09 GMT';
+};
+
+subtest 'expires()' => sub {
+ %adaptee = ();
+ is $adapter->expires, undef;
+
+ %adaptee = ( -date => 'Sat, 07 Jul 2012 05:05:09 GMT' );
+ $adapter->expires( '+3M' );
+ is_deeply \%adaptee, { -expires => '+3M' };
+
+ my $now = 1341637509;
+ $adapter->expires( $now );
+ is $adapter->expires, $now, 'get expires()';
+ is $adaptee{-expires}, $now;
+
+ $now++;
+ $adapter->expires( 'Sat, 07 Jul 2012 05:05:10 GMT' );
+ is $adapter->expires, $now, 'get expires()';
+};
View
35 t/22_date.t
@@ -1,35 +0,0 @@
-use strict;
-use warnings;
-use CGI::Header;
-use Test::More tests => 2;
-
-my %header;
-my $header = CGI::Header->new( \%header );
-
-subtest 'date()' => sub {
- %header = ();
- is $header->date, undef;
- my $now = 1341637509;
- $header->date( $now );
- is $header->date, $now;
- is $header{-date}, 'Sat, 07 Jul 2012 05:05:09 GMT';
-};
-
-subtest 'expires()' => sub {
- %header = ();
- is $header->expires, undef;
-
- %header = ( -date => 'Sat, 07 Jul 2012 05:05:09 GMT' );
- $header->expires( '+3M' );
- is_deeply \%header, { -expires => '+3M' };
-
- my $now = 1341637509;
- $header->expires( $now );
- is $header->expires, $now, 'get expires()';
- is $header{-expires}, $now;
-
- $now++;
- $header->expires( 'Sat, 07 Jul 2012 05:05:10 GMT' );
- is $header->expires, $now, 'get expires()';
- is $header{-expires}, 'Sat, 07 Jul 2012 05:05:10 GMT';
-};
View
0 t/15_p3p.t → t/22_p3p.t
File renamed without changes.
View
0 t/16_content_disposition.t → t/24_content_disposition.t
File renamed without changes.
View
0 t/24_as_string.t → t/30_as_string.t
File renamed without changes.

0 comments on commit e7e2e9c

Please sign in to comment.