Debian Codegraph @

t/charset_server.t

raw
1 use Test::More;
2 use strict;
3 use warnings;
4 use Encode;
5 use utf8;
6
7 use Plack::Test;
8 use HTTP::Request::Common;
9 use Ref::Util qw<is_coderef>;
10
11 {
12 package App;
13 use Dancer2;
14
15 get '/name/:name' => sub {
16 "Your name: " . params->{name};
17 };
18
19 post '/name' => sub {
20 "Your name: " . params->{name};
21 };
22
23 get '/unicode' => sub {
24 "cyrillic shcha \x{0429}",;
25 };
26
27 get '/symbols' => sub {
28 '⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘ ⚙';
29 };
30
31 set charset => 'utf-8';
32 }
33
34 my $app = Dancer2->psgi_app;
35 ok( is_coderef($app), 'Got app' );
36
37 test_psgi $app, sub {
38 my $cb = shift;
39 my $res = $cb->( POST "/name", [ name => 'vasya'] );
40
41 is $res->content_type, 'text/html';
42 ok $res->content_type_charset
43 ; # we always have charset if the setting is set
44 is $res->content, 'Your name: vasya';
45
46 $res = $cb->( GET "/unicode" );
47
48 is $res->content_type, 'text/html';
49 is $res->content_type_charset, 'UTF-8';
50 is $res->content, Encode::encode( 'utf-8', "cyrillic shcha \x{0429}" );
51
52 $res = $cb->( GET "/symbols" );
53 is $res->content_type, 'text/html';
54 is $res->content_type_charset, 'UTF-8';
55 is $res->content, Encode::encode( 'utf-8', "⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘ ⚙" );
56 };
57
58 done_testing();