File: charset_server.t

package info (click to toggle)
libdancer2-perl 0.207000%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,460 kB
  • sloc: perl: 8,069; makefile: 7
file content (58 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download | duplicates (4)
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
use Test::More;
use strict;
use warnings;
use Encode;
use utf8;

use Plack::Test;
use HTTP::Request::Common;
use Ref::Util qw<is_coderef>;

{
    package App;
    use Dancer2;

    get '/name/:name' => sub {
        "Your name: " . params->{name};
    };

    post '/name' => sub {
        "Your name: " . params->{name};
    };

    get '/unicode' => sub {
        "cyrillic shcha \x{0429}",;
    };

    get '/symbols' => sub {
        '⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘ ⚙';
    };

    set charset => 'utf-8';
}

my $app = Dancer2->psgi_app;
ok( is_coderef($app), 'Got app' );

test_psgi $app, sub {
    my $cb = shift;
    my $res = $cb->( POST "/name", [ name => 'vasya'] );

    is $res->content_type, 'text/html';
    ok $res->content_type_charset
      ;    # we always have charset if the setting is set
    is $res->content, 'Your name: vasya';

    $res = $cb->( GET "/unicode" );

    is $res->content_type,         'text/html';
    is $res->content_type_charset, 'UTF-8';
    is $res->content, Encode::encode( 'utf-8', "cyrillic shcha \x{0429}" );

    $res = $cb->( GET "/symbols" );
    is $res->content_type,         'text/html';
    is $res->content_type_charset, 'UTF-8';
    is $res->content, Encode::encode( 'utf-8', "⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘ ⚙" );
};

done_testing();