Skip to content

Commit

Permalink
Merge pull request #498 from ap/header-utils-tests
Browse files Browse the repository at this point in the history
Make Plack::Util::header_* less undertested
  • Loading branch information
miyagawa committed Feb 9, 2015
2 parents db4148f + 6dbe592 commit 7d6898c
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 63 deletions.
40 changes: 40 additions & 0 deletions t/Plack-Util/header_exists.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use strict;
use Test::More;
use Plack::Util;

{
my $headers = [];
ok !Plack::Util::header_exists($headers, 'Foo'), 'no headers';
}

{
my $headers = [ Baz => 'bar', Bar => 'baz' ];
ok !Plack::Util::header_exists($headers, 'Foo'), 'header does not exist';
}

{
my $headers = [ Foo => 'bar', Bar => 'baz' ];
ok Plack::Util::header_exists($headers, 'Foo'), 'header is first';
}

{
my $headers = [ Bar => 'foo', Foo => 'baz' ];
ok Plack::Util::header_exists($headers, 'Foo'), 'header is last';
}

{
my $headers = [ Bar => 'foo', Foo => 'baz', Baz => 'quux' ];
ok Plack::Util::header_exists($headers, 'Foo'), 'header in middle';
}

{
my $headers = [ Bar => 'foo', Foo => 'baz', Baz => 'foo', Foo => 'quux', Quux => 'bar' ];
ok Plack::Util::header_exists($headers, 'Foo'), 'header occurs multiple times';
}

{
my $headers = [ Foo => 'bar', Bar => 'baz' ];
ok Plack::Util::header_exists($headers, 'foo'), 'case-insensitive';
}

done_testing;
31 changes: 31 additions & 0 deletions t/Plack-Util/header_get.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use strict;
use Test::More;
use Test::Differences;
use Plack::Util;

{
my $headers = [];
is Plack::Util::header_get($headers, 'Foo'), undef, 'empty headers, scalar';
}

{
my $headers = [];
eq_or_diff [ Plack::Util::header_get($headers, 'Foo') ], [], 'empty headers, list';
}

{
my $headers = [ Foo => 'bar' ];
is Plack::Util::header_get($headers, 'Foo'), 'bar', 'header exists, scalar';
}

{
my $headers = [ Foo => 'bar' ];
eq_or_diff [ Plack::Util::header_get($headers, 'Foo') ], [ 'bar' ], 'header exists, list';
}

{
my $headers = [ Foo => 'bar' ];
is Plack::Util::header_get($headers, 'foo'), 'bar', 'case-insensitive'
}

done_testing;
24 changes: 24 additions & 0 deletions t/Plack-Util/header_push.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use strict;
use Test::More;
use Test::Differences;
use Plack::Util;

{
my $headers = [];
Plack::Util::header_push($headers, Foo => 'quox');
eq_or_diff $headers, [ Foo => 'quox' ], 'push to empty headers';
}

{
my $headers = [ Bar => 'baz' ];
Plack::Util::header_push($headers, Foo => 'quox');
eq_or_diff $headers, [ Bar => 'baz', Foo => 'quox' ], 'push to non-empty headers';
}

{
my $headers = [ Foo => 'bar', Bar => 'baz' ];
Plack::Util::header_push($headers, Foo => 'quox');
eq_or_diff $headers, [ Foo => 'bar', Bar => 'baz', Foo => 'quox' ], 'push with previous header values';
}

done_testing;
48 changes: 48 additions & 0 deletions t/Plack-Util/header_remove.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use strict;
use Test::More;
use Test::Differences;
use Plack::Util;

{
my $headers = [];
Plack::Util::header_remove($headers, 'Foo');
eq_or_diff $headers, [], 'empty headers';
}

{
my $headers = [ Bar => 'baz' ];
Plack::Util::header_remove($headers, 'Foo');
eq_or_diff $headers, [ Bar => 'baz' ], 'other headers only';
}

{
my $headers = [ Foo => 'bar', Bar => 'foo' ];
Plack::Util::header_remove($headers, 'Foo');
eq_or_diff $headers, [ Bar => 'foo' ], 'header is first';
}

{
my $headers = [ Bar => 'foo', Foo => 'bar' ];
Plack::Util::header_remove($headers, 'Foo');
eq_or_diff $headers, [ Bar => 'foo' ], 'header is last';
}

{
my $headers = [ Bar => 'foo', Foo => 'baz', Baz => 'quux' ];
Plack::Util::header_remove($headers, 'Foo');
eq_or_diff $headers, [ Bar => 'foo', Baz => 'quux' ], 'header in middle';
}

{
my $headers = [ Bar => 'foo', Foo => 'baz', Baz => 'foo', Foo => 'quux', Quux => 'bar' ];
Plack::Util::header_remove($headers, 'Foo');
eq_or_diff $headers, [ Bar => 'foo', Baz => 'foo', Quux => 'bar' ], 'header occurs multiple times';
}

{
my $headers = [ Foo => 'bar', Bar => 'baz' ];
Plack::Util::header_remove($headers, 'foo');
eq_or_diff $headers, [ Bar => 'baz' ], 'case-insensitive';
}

done_testing;
36 changes: 36 additions & 0 deletions t/Plack-Util/header_set.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use strict;
use Test::More;
use Test::Differences;
use Plack::Util;

{
my $headers = [];
Plack::Util::header_set($headers, Bar => 'baz');
eq_or_diff $headers, [ Bar => 'baz' ], 'empty headers';
}

{
my $headers = [ Foo => 'bar' ];
Plack::Util::header_set($headers, Bar => 'baz');
eq_or_diff $headers, [ Foo => 'bar', Bar => 'baz' ], 'other headers only';
}

{
my $headers = [ Foo => 'bar' ];
Plack::Util::header_set($headers, Foo => 'baz');
eq_or_diff $headers, [ Foo => 'baz' ], 'one matching header';
}

{
my $headers = [ Foo => 'bar', Foo => 'baz' ];
Plack::Util::header_set($headers, Foo => 'quox');
eq_or_diff $headers, [ Foo => 'quox' ], 'several matching headers';
}

{
my $headers = [ Foo => 'bar' ];
Plack::Util::header_set($headers, foo => 'baz');
eq_or_diff $headers, [ Foo => 'baz' ], 'case-insensitive';
}

done_testing;
63 changes: 0 additions & 63 deletions t/Plack-Util/headers.t

This file was deleted.

0 comments on commit 7d6898c

Please sign in to comment.