Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 152 lines (139 sloc) 3.751 kb
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
#!/usr/bin/perl
#

use strict;
use C4::Interface::CGI::Output; #

use vars qw( @tests );
use vars qw( $loaded );

BEGIN {
   @tests = (
   [
      'Normal HTML without meta tag',
      sub { guesscharset($_[0]) },
      undef,
      <<EOF
<title>control case</title>
EOF
   ], [
      'Result of guesscharset with normal HTML with irrelevant meta tag',
      sub { guesscharset($_[0]) },
      undef,
      <<EOF
<meta http-equiv="Content-Language" content="zh-TW">
EOF
   ], [
      'Result of guesstype with normal HTML with irrelevant meta tag',
      sub { guesstype($_[0]) },
      'text/html',
      <<EOF
<meta http-equiv="Content-Language" content="zh-TW">
EOF
   ], [
      'Result of guesscharset with normal HTML with relevant meta tag',
      sub { guesscharset($_[0]) },
      'big5',
      <<EOF
<meta http-equiv="Content-Type" content="text/html; charset=big5">
EOF
   ], [
      'Result of guesstype with normal HTML with relevant meta tag',
      sub { guesstype($_[0]) },
      'text/html; charset=big5',
      <<EOF
<meta http-equiv="Content-Type" content="text/html; charset=big5">
EOF
   ], [
      'Variant 1 using single quotes',
      sub { guesstype($_[0]) },
      'text/html; charset=iso-2022-jp',
      <<EOF
<meta http-equiv="Content-Type" content='text/html; charset=iso-2022-jp'>
EOF
   ], [
      'Variant 2 using single quotes',
      sub { guesstype($_[0]) },
      'text/html; charset=utf-8',
      <<EOF
<meta http-equiv='Content-Type' content="text/html; charset=utf-8">
EOF
   ], [
      'Unquoted Content-Type',
      sub { guesstype($_[0]) },
      'text/html; charset=big5',
      <<EOF
<meta http-equiv=Content-Type content="text/html; charset=big5">
EOF
   ], [
      'XML syntax',
      sub { guesstype($_[0]) },
      'text/html; charset=iso-8859-2',
      <<EOF
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-2" />
EOF
   ], [
      'Expected attributes in reverse order',
      sub { guesstype($_[0]) },
      'text/html; charset=big5',
      <<EOF
<meta content="text/html; charset=big5" http-equiv="Content-Type">
EOF
   ], [
      'Extra whitespace at end',
      sub { guesstype($_[0]) },
      'text/html; charset=big5',
      <<EOF
<meta http-equiv="Content-Type" content="text/html; charset=big5" >
EOF
   ], [
      'Multiple lines',
      sub { guesstype($_[0]) },
      'text/html; charset=big5',
      <<EOF
<meta
http-equiv="Content-Type"
content="text/html; charset=big5"
>
EOF
   ], [
      # FIXME - THIS IS NOT A WELL-WRITTEN TEST CASE!!!
      'With surrounding HTML',
      sub { guesstype($_[0]) },
      'text/html; charset=us-ascii',
      <<EOF
<html>
<head>
<title>Test case with surrounding HTML</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
The return value should not be contaiminated with any surround HTML
FIXME: Auth.pm returns in code that can contaminate the charset
FIXME: if we do not explicitly disallow whitespace in the charset
</body>
</html>
EOF
   ],
);
}

BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
END {print "not ok 1\n" unless $loaded;}
$loaded = 1;


# Run all tests in sequence
for (my $i = 1; $i <= scalar @tests; $i += 1) {
   my $test = $tests[$i - 1];
   my($title, $f, $expected, $input) = @$test;
   die "not ok $i (malformed test case)\n"
      unless @$test == 4 && ref $f eq 'CODE';

   my $output = &$f($input);
   if (
(!defined $output && !defined $expected)
      || (defined $output && defined $expected && $output eq $expected)
   ) {
      print "ok $i - $title\n";
   } else {
      print "not ok $i - $title: got ",
(defined $output? "\"$output\"": 'undef'),
', expected ',
(defined $expected? "\"$expected\"": 'undef'),
"\n";
   }
}





Something went wrong with that request. Please try again.