Debian Codegraph @

t/01_parse.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use WWW::Form::UrlEncoded::XS qw/parse_urlencoded parse_urlencoded_arrayref/;
5 use JSON;
6
7 is_deeply([parse_urlencoded(undef)], []);
8 is_deeply(parse_urlencoded_arrayref(undef), []);
9
10 while (<DATA>) {
11 chomp;
12 next unless $_;
13 my ($s,$t) = split /\s+=>\s/, $_,2;
14 $s =~ s/'//g;
15 my @param = parse_urlencoded($s);
16 is JSON::encode_json(\@param), $t, $s;
17 my $param = parse_urlencoded_arrayref($s);
18 is JSON::encode_json($param), $t, $s;
19
20 }
21
22 done_testing();
23
24 __DATA__
25 'a=b&c=d' => ["a","b","c","d"]
26 'a=b;c=d' => ["a","b","c","d"]
27 'a=1&b=2;c=3' => ["a","1","b","2","c","3"]
28 'a==b&c==d' => ["a","=b","c","=d"]
29 'a=b& c=d' => ["a","b","c","d"]
30 'a=b; c=d' => ["a","b","c","d"]
31 'a=b; c =d' => ["a","b","c ","d"]
32 'a=b;c= d ' => ["a","b","c"," d "]
33 'a=b&+c=d' => ["a","b"," c","d"]
34 'a=b&+c+=d' => ["a","b"," c ","d"]
35 'a=b&c=+d+' => ["a","b","c"," d "]
36 'a=b&%20c=d' => ["a","b"," c","d"]
37 'a=b&%20c%20=d' => ["a","b"," c ","d"]
38 'a=b&c=%20d%20' => ["a","b","c"," d "]
39 'a&c=d' => ["a","","c","d"]
40 'a=b&=d' => ["a","b","","d"]
41 'a=b&=' => ["a","b","",""]
42 'a=&' => ["a","","",""]
43 '&' => ["","","",""]
44 '=' => ["",""]
45 '' => []
46