Imported Upstream version 0.18
This commit is contained in:
171
t/01-sanity.t
Normal file
171
t/01-sanity.t
Normal file
@@ -0,0 +1,171 @@
|
||||
#use CGI::Cookie::XS;
|
||||
|
||||
use t::TestCookie;
|
||||
|
||||
plan tests => 1 * blocks();
|
||||
|
||||
#test 'CGI::Cookie';
|
||||
no_diff;
|
||||
|
||||
run_tests;
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: complex cookie
|
||||
--- cookie
|
||||
foo=a%20phrase;haha; bar=yes%2C%20a%20phrase; baz=%5Ewibble&leiyh; qux=%27
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'bar' => [
|
||||
'yes, a phrase'
|
||||
],
|
||||
'baz' => [
|
||||
'^wibble',
|
||||
'leiyh'
|
||||
],
|
||||
'foo' => [
|
||||
'a phrase'
|
||||
],
|
||||
'qux' => [
|
||||
'\''
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 2: foo=
|
||||
--- cookie
|
||||
foo=
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'foo' => []
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 3: foo
|
||||
--- cookie
|
||||
foo
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 4: foo bar
|
||||
--- cookie
|
||||
foo bar
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 5: &
|
||||
--- cookie
|
||||
&
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 6: ;
|
||||
--- cookie
|
||||
;
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 7: ,
|
||||
--- cookie
|
||||
,
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 8: &&
|
||||
--- cookie
|
||||
&&;
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 9: trailing spaces and leading spaces should be trimmed
|
||||
--- cookie
|
||||
foo=a%3A;
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'foo' => [
|
||||
'a:'
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 10: trailing spaces which should be reserved.
|
||||
--- cookie
|
||||
foo=a%3A
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'foo' => [
|
||||
'a: '
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 11: , sperated values
|
||||
--- cookie
|
||||
foo=bar,foo2=bar2, foo3=bar3;foo4 =a&b&c; foo5=a;b
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'foo' => [
|
||||
'bar'
|
||||
],
|
||||
'foo2' => [
|
||||
'bar2'
|
||||
],
|
||||
'foo3' => [
|
||||
'bar3'
|
||||
],
|
||||
'foo4 ' => [
|
||||
'a',
|
||||
'b',
|
||||
'c'
|
||||
],
|
||||
'foo5' => [
|
||||
'a'
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 12: leading and trailing spaces
|
||||
--- cookie
|
||||
foo = bar ; foo2 = bar2
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'foo ' => [
|
||||
' bar '
|
||||
],
|
||||
'foo2 ' => [
|
||||
' bar2 '
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 13: encoded leading and trailing spaces
|
||||
--- cookie
|
||||
%20foo = bar ;%20foo2 = bar2
|
||||
--- out
|
||||
$VAR1 = {
|
||||
' foo ' => [
|
||||
' bar '
|
||||
],
|
||||
' foo2 ' => [
|
||||
' bar2 '
|
||||
]
|
||||
};
|
||||
|
||||
28
t/02-overflow.t
Normal file
28
t/02-overflow.t
Normal file
@@ -0,0 +1,28 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#use Smart::Comments;
|
||||
use Test::More tests => 7;
|
||||
BEGIN { use_ok('CGI::Cookie::XS'); }
|
||||
|
||||
my $COOKIE_LEN_LIMIT = 1024 * 4;
|
||||
|
||||
{
|
||||
my $val_len = $COOKIE_LEN_LIMIT - 3;
|
||||
my $cookie = 'a=' . ('a' x $val_len);
|
||||
my $res = CGI::Cookie::XS->parse($cookie);
|
||||
ok $res, 'res okay';
|
||||
ok $res->{a}, 'var a parsed';
|
||||
is $res->{a}->[0], 'a' x $val_len, "value okay for var a";
|
||||
}
|
||||
|
||||
{
|
||||
my $val_len = $COOKIE_LEN_LIMIT - 3;
|
||||
my $cookie = 'a=' . ('a' x $COOKIE_LEN_LIMIT);
|
||||
my $res = CGI::Cookie::XS->parse($cookie);
|
||||
ok $res, 'res okay';
|
||||
ok $res->{a}, 'var a parsed';
|
||||
### Len: length($res->{a}->[0])
|
||||
is $res->{a}->[0], 'a' x $val_len, "value okay for var a";
|
||||
}
|
||||
|
||||
65
t/03-bug.t
Normal file
65
t/03-bug.t
Normal file
@@ -0,0 +1,65 @@
|
||||
use t::TestCookie;
|
||||
|
||||
plan tests => 1 * blocks();
|
||||
|
||||
#test 'CGI::Cookie';
|
||||
run_tests;
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: successive =
|
||||
# http://rt.cpan.org/Public/Bug/Display.html?id=34238
|
||||
--- cookie
|
||||
foo=ba=r
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'foo' => [
|
||||
'ba=r'
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
=== TEST 2: empty cookie
|
||||
# http://rt.cpan.org/Public/Bug/Display.html?id=39120
|
||||
--- cookie
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 3: invalid cookie (1)
|
||||
# http://rt.cpan.org/Public/Bug/Display.html?id=39120
|
||||
--- cookie
|
||||
a
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 4: invalid cookie (2)
|
||||
# http://rt.cpan.org/Public/Bug/Display.html?id=39120
|
||||
--- cookie
|
||||
this-is-not-a-cookie
|
||||
--- out
|
||||
$VAR1 = {};
|
||||
|
||||
|
||||
|
||||
=== TEST 5: empty values
|
||||
rt.cpan.org #49302
|
||||
--- cookie: lastvisit=1251731074; sessionlogin=1251760758; username=; password=; remember_login=; admin_button=
|
||||
--- out
|
||||
$VAR1 = {
|
||||
'admin_button' => [],
|
||||
'lastvisit' => [
|
||||
'1251731074'
|
||||
],
|
||||
'password' => [],
|
||||
'remember_login' => [],
|
||||
'sessionlogin' => [
|
||||
'1251760758'
|
||||
],
|
||||
'username' => []
|
||||
};
|
||||
|
||||
9
t/99-pod-coverage.t
Normal file
9
t/99-pod-coverage.t
Normal file
@@ -0,0 +1,9 @@
|
||||
use Test::More;
|
||||
|
||||
# XXX we need more POD...
|
||||
#my $skip_all = 0;
|
||||
eval "use Test::Pod::Coverage";
|
||||
#plan skip_all => "We know we don't have enough POD :(" if $skip_all;
|
||||
plan skip_all => "Test::Pod::Coverage required for testing POD coverage" if $@;
|
||||
all_pod_coverage_ok();
|
||||
|
||||
5
t/99-pod.t
Normal file
5
t/99-pod.t
Normal file
@@ -0,0 +1,5 @@
|
||||
use Test::More;
|
||||
eval "use Test::Pod 1.00";
|
||||
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
|
||||
all_pod_files_ok();
|
||||
|
||||
35
t/TestCookie.pm
Normal file
35
t/TestCookie.pm
Normal file
@@ -0,0 +1,35 @@
|
||||
use Test::Base -Base;
|
||||
|
||||
#use Smart::Comments;
|
||||
use Data::Dumper;
|
||||
|
||||
$Data::Dumper::Sortkeys = 1;
|
||||
|
||||
my $package = 'CGI::Cookie::XS';
|
||||
|
||||
sub test ($) {
|
||||
$package = shift;
|
||||
}
|
||||
|
||||
sub run_tests () {
|
||||
eval "use $package;";
|
||||
if ($@) { die $@ }
|
||||
for my $block (blocks()) {
|
||||
my $name = $block->name;
|
||||
my $cookie = $block->cookie;
|
||||
die "$name - No --- cookie specified" if !defined $cookie;
|
||||
chomp $cookie;
|
||||
### $cookie
|
||||
my $res = $package->parse($cookie);
|
||||
if ($package eq 'CGI::Cookie') {
|
||||
for my $key (keys %$res) {
|
||||
$res->{$key} = $res->{$key}->{value};
|
||||
}
|
||||
}
|
||||
my $out = $block->out;
|
||||
die "$name - No --- out specified" if !defined $out;
|
||||
is Dumper($res), $out, "$name - out okay";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user