File: headers-util.t

package info (click to toggle)
libwww-perl 5.36-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 848 kB
  • ctags: 400
  • sloc: perl: 6,366; makefile: 51; sh: 6
file content (61 lines) | stat: -rw-r--r-- 1,748 bytes parent folder | download | duplicates (3)
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
use strict;
use HTTP::Headers::Util qw(split_header_words join_header_words);

my $extra_tests = 2;

my @s_tests = (

   ["foo"                     => "foo"],
   ["foo=bar"                 => "foo=bar"],
   ["   foo   "               => "foo"],
   ["foo="                    => 'foo=""'],
   ["foo=bar bar=baz"         => "foo=bar; bar=baz"],
   ["foo=bar;bar=baz"         => "foo=bar; bar=baz"],
   ['foo bar baz'             => "foo; bar; baz"],
   ['foo="\"" bar="\\\\"'     => 'foo="\""; bar="\\\\"'],
   ['foo,,,bar'               => 'foo, bar'],
   ['foo=bar,bar=baz'         => 'foo=bar, bar=baz'],

   ['text/html; charset=iso-8859-1' =>
    'text/html; charset="iso-8859-1"'],

   ['foo="bar"; port="80,81"; discard, bar=baz' =>
    'foo=bar; port="80,81"; discard, bar=baz'],

   ['Basic realm="\"foo\\\\bar\""' =>
    'Basic; realm="\"foo\\\\bar\""'],
);

print "1..", @s_tests + $extra_tests, "\n";

my $testno = 1;

print "split_header_words() tests\n";
for (@s_tests) {
   my($arg, $expect) = @$_;
   my @arg = ref($arg) ? @$arg : $arg;

   my $res = join_header_words(split_header_words(@arg));
   if ($res ne $expect) {
       print "\nUnexpected result: '$res'\n";
       print "         Expected: '$expect'\n";
       print "  when parsing '", join(", ", @arg), "'\n";
       eval {
	   require Data::Dumper;
           my @p = split_header_words(@arg);
           print Data::Dumper::Dumper(\@p);
       };
       print "not ";
   }
   print "ok ", $testno++, "\n";
}


print "Extra tests\n";
# some extra tests
print "not " unless join_header_words("foo" => undef, "bar" => "baz")
                    eq "foo; bar=baz";
print "ok ", $testno++, "\n";

print "not " unless join_header_words() eq "";
print "ok ", $testno++, "\n";