File: 02_build.t

package info (click to toggle)
libwww-form-urlencoded-xs-perl 0.28-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 320 kB
  • sloc: perl: 10; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,725 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
use strict;
use warnings;
use Test::More;
use WWW::Form::UrlEncoded::XS qw/build_urlencoded build_urlencoded_utf8/;
use JSON;

my @data = (
    ['a'=>'b'] => 'a=b',
    [['a'=>'b']] => 'a=b',
    [{'a'=>'b'}] => 'a=b',
    ['a'=>['b','c']] => 'a=b&a=c',
    [['a'=>['b','c']]] => 'a=b&a=c',
    [{'a'=>['b','c']}] => 'a=b&a=c',
    ['a'=>'b','c'=>'d'] => 'a=b&c=d',
    [' a '=>' b '] => '+a+=+b+',
    ['a'=>'b','c'=>'d',';'] => 'a=b;c=d',
    [['a'=>['b','c']],';'] => 'a=b;a=c',
    [{'a'=>['b','c']},';'] => 'a=b;a=c',
    ['a'=>'b','c'=>'d',';&'] => 'a=b;&c=d',
    [['a'=>['b','c']],';&'] => 'a=b;&a=c',
    [{'a'=>['b','c']},';&'] => 'a=b;&a=c',
    ['a'=>'b','c'=> undef,';'] => 'a=b;c=',
    ['a'] => 'a=',
    ['a'=>undef] => 'a=',
    ['a'=>'',''=>''] => 'a=&=',
    [undef] => '=',
    [] => '',
);

while ( @data ) {
    my $data = shift @data;
    my $test = shift @data;
    is( build_urlencoded(@$data), $test, JSON::encode_json($data));
}

is( build_urlencoded([ foo => "\xE5", bar => "\x{263A}" ]), 'foo=%E5&bar=%E2%98%BA');
is( build_urlencoded_utf8([ foo => "\xE5", bar => "\x{263A}" ]), 'foo=%C3%A5&bar=%E2%98%BA');
is( build_urlencoded_utf8([ "\xE5" => "foo", "\x{263A}" => "bar" ]), '%C3%A5=foo&%E2%98%BA=bar');
is( build_urlencoded_utf8([ foo => "\x{263A}", bar => "\x{263A}" ],"\xE5"), 'foo=%E2%98%BAƄbar=%E2%98%BA');

for (1..10){
  like( build_urlencoded({aa => [ 1, undef, 3 ],bb => [ 1, 2, 3 ]}), qr!(aa=1&aa=&aa=3&bb=1&bb=2&bb=3|bb=1&bb=2&bb=3&aa=1&aa=&aa=3)!);
  like( build_urlencoded_utf8({aa => [ 1, undef, 3 ],bb => [ 1, 2, 3 ]}), qr!(aa=1&aa=&aa=3&bb=1&bb=2&bb=3|bb=1&bb=2&bb=3&aa=1&aa=&aa=3)!);
}

is( build_urlencoded( 'Test' => ( 'x' x 50003 ) ), 'Test='.('x'x50003) );

done_testing;