File: sort.t

package info (click to toggle)
libhttp-cookiejar-perl 0.006-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 252 kB
  • sloc: perl: 435; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use Test::Deep '!blessed';
use Test::MockTime;

use HTTP::CookieJar;

my @cases = (
    {
        label   => "path length",
        request => "http://example.com/foo/bar/",
        cookies => [
            [ "http://example.com/foo/bar/", "SID=2; Path=/" ],
            [ "http://example.com/foo/bar/", "SID=1; Path=/foo" ],
            [ "http://example.com/foo/bar/", "SID=0; Path=/foo/bar" ],
        ],
    },
    {
        label   => "creation time",
        request => "http://foo.bar.baz.example.com/",
        cookies => [
            [ "http://foo.bar.baz.example.com/", "SID=0; Path=/; Domain=bar.baz.example.com" ],
            [ "http://foo.bar.baz.example.com/", "SID=1; Path=/; Domain=baz.example.com" ],
            [ "http://foo.bar.baz.example.com/", "SID=2; Path=/; Domain=example.com" ],
        ],
    },
);

for my $c (@cases) {
    my $jar    = HTTP::CookieJar->new;
    my $offset = 0;
    for my $cookie ( @{ $c->{cookies} } ) {
        Test::MockTime::set_relative_time($offset);
        $jar->add(@$cookie);
        $offset += 10;
    }
    my @cookies = $jar->cookies_for( $c->{request} );
    my @vals = map { $_->{value} } @cookies;
    cmp_deeply \@vals, [ 0 .. $#vals ], $c->{label} or diag explain \@cookies;
}

done_testing;
#
# This file is part of HTTP-CookieJar
#
# This software is Copyright (c) 2013 by David Golden.
#
# This is free software, licensed under:
#
#   The Apache License, Version 2.0, January 2004
#