Debian lenny version packages
[pkg-perl] / deb-src / libwww-perl / libwww-perl-5.813 / t / base / headers-util.t
1 use strict;
2 use HTTP::Headers::Util qw(split_header_words join_header_words);
3
4 my $extra_tests = 2;
5
6 my @s_tests = (
7
8    ["foo"                     => "foo"],
9    ["foo=bar"                 => "foo=bar"],
10    ["   foo   "               => "foo"],
11    ["foo="                    => 'foo=""'],
12    ["foo=bar bar=baz"         => "foo=bar; bar=baz"],
13    ["foo=bar;bar=baz"         => "foo=bar; bar=baz"],
14    ['foo bar baz'             => "foo; bar; baz"],
15    ['foo="\"" bar="\\\\"'     => 'foo="\""; bar="\\\\"'],
16    ['foo,,,bar'               => 'foo, bar'],
17    ['foo=bar,bar=baz'         => 'foo=bar, bar=baz'],
18
19    ['text/html; charset=iso-8859-1' =>
20     'text/html; charset=iso-8859-1'],
21
22    ['foo="bar"; port="80,81"; discard, bar=baz' =>
23     'foo=bar; port="80,81"; discard, bar=baz'],
24
25    ['Basic realm="\"foo\\\\bar\""' =>
26     'Basic; realm="\"foo\\\\bar\""'],
27 );
28
29 print "1..", @s_tests + $extra_tests, "\n";
30
31 my $testno = 1;
32
33 print "split_header_words() tests\n";
34 for (@s_tests) {
35    my($arg, $expect) = @$_;
36    my @arg = ref($arg) ? @$arg : $arg;
37
38    my $res = join_header_words(split_header_words(@arg));
39    if ($res ne $expect) {
40        print "\nUnexpected result: '$res'\n";
41        print "         Expected: '$expect'\n";
42        print "  when parsing '", join(", ", @arg), "'\n";
43        eval {
44            require Data::Dumper;
45            my @p = split_header_words(@arg);
46            print Data::Dumper::Dumper(\@p);
47        };
48        print "not ";
49    }
50    print "ok ", $testno++, "\n";
51 }
52
53
54 print "Extra tests\n";
55 # some extra tests
56 print "not " unless join_header_words("foo" => undef, "bar" => "baz")
57                     eq "foo; bar=baz";
58 print "ok ", $testno++, "\n";
59
60 print "not " unless join_header_words() eq "";
61 print "ok ", $testno++, "\n";