-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from ap/header-utils-tests
Make Plack::Util::header_* less undertested
- Loading branch information
Showing
6 changed files
with
179 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.