File: type.t

package info (click to toggle)
libcgi-pm-perl 4.68-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,028 kB
  • sloc: perl: 6,082; makefile: 9
file content (101 lines) | stat: -rw-r--r-- 2,513 bytes parent folder | download | duplicates (5)
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
use strict;
use CGI;
use Test::More;

{
    my $cgi = CGI->new;
    my $got = $cgi->header( -type => 'text/plain' );
    my $expected = 'Content-Type: text/plain; charset=ISO-8859-1'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'type';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header( -type => q{} );
    my $expected = $CGI::CRLF x 2;
    is $got, $expected, 'type empty string';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header( -type => 'text/plain; charset=utf-8' );
    my $expected = 'Content-Type: text/plain; charset=utf-8'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'type defines charset';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header(
        '-type'    => 'text/plain',
        '-charset' => 'utf-8',
    );
    my $expected = 'Content-Type: text/plain; charset=utf-8'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'type and charset';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header(
        '-type'    => q{},
        '-charset' => 'utf-8',
    );
    my $expected = $CGI::CRLF x 2;
    is $got, $expected, 'type and charset, type is empty string';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header(
        '-type'    => 'text/plain; charset=utf-8',
        '-charset' => q{},
    );
    my $expected = 'Content-Type: text/plain; charset=utf-8'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'type and charset, charset is empty string';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header(
        '-type'    => 'text/plain; charset=utf-8',
        '-charset' => 'EUC-JP',
    );
    my $expected = 'Content-Type: text/plain; charset=utf-8'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'type and charset, type defines charset';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header( -type => 'image/gif' );
    my $expected = 'Content-Type: image/gif; charset=ISO-8859-1'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'image type, no charset';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header(
		-type    => 'image/gif',
		-charset => '',
	);
    my $expected = 'Content-Type: image/gif'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'image type, no charset';
}

{
    my $cgi = CGI->new;
    my $got = $cgi->header(
        -type    => 'image/gif',
        -charset => 'utf-8',
    );
    my $expected = 'Content-Type: image/gif; charset=utf-8'
                 . $CGI::CRLF x 2;
    is $got, $expected, 'image type, forced charset';
}

done_testing;