File: util.t

package info (click to toggle)
liboauth-lite2-perl 0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 592 kB
  • sloc: perl: 2,658; makefile: 8
file content (56 lines) | stat: -rw-r--r-- 1,267 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
54
55
56
use strict;
use warnings;

use Test::More tests => 11;

use OAuth::Lite2::Util qw(
    encode_param
    decode_param
    parse_content
    build_content
);

use Hash::MultiValue;

TEST_ENCODE: {

my $param = q{123 @#$%&hoge hoge+._-~};
my $encoded = encode_param($param);
is($encoded, q{123%20%40%23%24%25%26hoge%20hoge%2B._-~});
my $decoded = decode_param($encoded);
is($decoded, $param);

};

TEST_PARSE_CONTENT: {
    my $content = q{aaa=bbb&bbb=ccc&ddd=eee&aaa=ddd};
    my $params  = parse_content($content);
    is($params->{bbb}, 'ccc');
    is($params->get('bbb'), 'ccc');
    ok(!$params->get('fff'));
    is($params->get('aaa'), 'ddd');
    my @aaa = $params->get_all('aaa');
    is(scalar @aaa, 2);
    is($aaa[0], 'bbb');
    is($aaa[1], 'ddd');
};

TEST_BUILD_CONTENT: {
    my $params = {
        aaa => 'bbb',
        bbb => 'ccc',
        ccc => 'ddd',
        ddd => ['eee', 'fff'],
    };
    my $content = build_content($params);
    is($content, 'aaa=bbb&bbb=ccc&ccc=ddd&ddd=eee&ddd=fff');
    $params = Hash::MultiValue->new(
        aaa => 'bbb',
        bbb => 'ccc',
        ccc => 'ddd',
        ddd => 'eee',
        ddd => 'fff',
    );
    $content = build_content($params);
    is($content, 'aaa=bbb&bbb=ccc&ccc=ddd&ddd=eee&ddd=fff');
};