More VMS tweaks from Craig A. Berry.
[p5sagit/p5-mst-13.2.git] / t / lib / cgi-esc.t
1 #!/usr/local/bin/perl -w
2
3 BEGIN {
4     chdir('t') if -d 't';
5     @INC = '../lib';
6 }
7
8 # Test ability to escape() and unescape() punctuation characters
9 # except for qw(- . _).
10 ######################### We start with some black magic to print on failure.
11 use lib '../blib/lib','../blib/arch';
12
13 BEGIN {$| = 1; print "1..59\n"; }
14 END {print "not ok 1\n" unless $loaded;}
15 use Config;
16 use CGI::Util qw(escape unescape);
17 $loaded = 1;
18 print "ok 1\n";
19
20 ######################### End of black magic.
21
22 # util
23 sub test {
24     local($^W) = 0;
25     my($num, $true,$msg) = @_;
26     print($true ? "ok $num\n" : "not ok $num $msg\n");
27 }
28
29 # ASCII order, ASCII codepoints, ASCII repertoire
30
31 my %punct = (
32     ' ' => '20',  '!' => '21',  '"' => '22',  '#' =>  '23', 
33     '$' => '24',  '%' => '25',  '&' => '26',  '\'' => '27', 
34     '(' => '28',  ')' => '29',  '*' => '2A',  '+' =>  '2B', 
35     ',' => '2C',                              '/' =>  '2F',  # '-' => '2D',  '.' => '2E' 
36     ':' => '3A',  ';' => '3B',  '<' => '3C',  '=' =>  '3D', 
37     '>' => '3E',  '?' => '3F',  '[' => '5B',  '\\' => '5C', 
38     ']' => '5D',  '^' => '5E',                '`' =>  '60',  # '_' => '5F',
39     '{' => '7B',  '|' => '7C',  '}' => '7D',  '~' =>  '7E', 
40          );
41
42 # The sort order may not be ASCII on EBCDIC machines:
43
44 my $i = 1;
45
46 foreach(sort(keys(%punct))) { 
47     $i++;
48     my $escape = "AbC\%$punct{$_}dEF";
49     my $cgi_escape = escape("AbC$_" . "dEF");
50     test($i, $escape eq $cgi_escape , "# $escape ne $cgi_escape");
51     $i++;
52     my $unescape = "AbC$_" . "dEF";
53     my $cgi_unescape = unescape("AbC\%$punct{$_}dEF");
54     test($i, $unescape eq $cgi_unescape , "# $unescape ne $cgi_unescape");
55 }
56