File: 020-priority-list.t

package info (click to toggle)
libhttp-headers-actionpack-perl 0.09-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: perl: 2,614; makefile: 2
file content (109 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download | duplicates (5)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Fatal;

BEGIN {
    use_ok('HTTP::Headers::ActionPack::PriorityList');
}

sub test_priority_list {
    my $q = shift;

    isa_ok($q, 'HTTP::Headers::ActionPack::PriorityList');

    is_deeply($q->get(2.5), ["gorch"], '... got the right item for the priority');
    is($q->priority_of("foo"), 1.0, '... got the right priority for the item');

    is_deeply($q->get(3.0), ["baz", "foobaz"], '... got the right item for the priority');

    is_deeply(
        [ $q->iterable ],
        [
            [ 3, 'baz' ],
            [ 3, 'foobaz' ],
            [ 2.5, 'gorch' ],
            [ 2, 'bar' ],
            [ 1, 'foo' ]
        ],
        '... got the iterable form'
    );

    is(
        $q->as_string,
        'baz; q="3", foobaz; q="3", gorch; q="2.5", bar; q="2", foo; q="1"',
        '... got the right string form'
    );
}

test_priority_list(
    HTTP::Headers::ActionPack::PriorityList->new(
         [ 1.0, "foo"    ],
         [ 2.0, "bar"    ],
         [ 3.0, "baz"    ],
         [ 3.0, "foobaz" ],
         [ 2.5, "gorch"  ],
    )
);

test_priority_list(
    HTTP::Headers::ActionPack::PriorityList->new_from_string(
        'foo; q="1.0", bar; q="2.0", baz; q="3.0", foobaz; q="3.0", gorch; q="2.5"'
    )
);

{
    my $q = HTTP::Headers::ActionPack::PriorityList->new;
    $q->add( 1.0, "foo" );
    $q->add( 2.0, "bar" );
    $q->add( 3.0, "baz" );
    $q->add( 3.0, "foobaz" );
    $q->add( 2.5, "gorch" );

    test_priority_list( $q );
}

{
    my $q = HTTP::Headers::ActionPack::PriorityList->new_from_string( "application/xml;q=0.7" );

    is_deeply($q->get(0.7), ["application/xml"], '... got the right item for the priority');
    is($q->priority_of("application/xml"), 0.7, '... got the right priority for the item');

    is_deeply(
        [ $q->iterable ],
        [
            [ 0.7, "application/xml" ],
        ],
        '... got the iterable form'
    );

    is(
        $q->as_string,
        'application/xml; q="0.7"',
        '... got the right string form'
    );
}

{
    my $q = HTTP::Headers::ActionPack::PriorityList->new_from_string( "foo, bar" );
    is_deeply(
        [ $q->iterable ],
        [
            [ 1, "foo" ],
            [ 1, "bar" ],
        ],
        '... got the iterable form'
    );

    is(
        $q->as_string,
        'foo; q="1", bar; q="1"',
        '... got the right string form'
    );
}


done_testing;