File: encoding.t

package info (click to toggle)
libwww-mechanize-perl 1.71-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 620 kB
  • sloc: perl: 3,272; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 739 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

use strict;
use warnings;

use constant PAIRS => {
    'http://delicious.com/'
        => 'utf-8',
    'http://www.liveinternet.ru/users/dashdi/blog'
        => '(?:cp|windows-)1251',
};

use Test::More tests => (4 * keys %{+PAIRS}) + 1;
use Encode;

BEGIN {
    use_ok( 'WWW::Mechanize' );
}

my %pairs = %{+PAIRS};
for my $url ( sort keys %pairs ) {
    my $want_encoding = $pairs{$url};

    my $mech = WWW::Mechanize->new;
    isa_ok( $mech, 'WWW::Mechanize' );

    $mech->get( $url );
    is( $mech->response->code, 200, "Fetched $url" );

    like( $mech->res->content_charset, qr/$want_encoding/i,
        "   ... Got encoding $want_encoding" );
    ok( Encode::is_utf8( $mech->content ), 'Got back UTF-8' );
}