Debian Codegraph @

t/http_status.t

raw
1 use strict;
2 use warnings;
3 use Test::More tests => 5;
4
5 use Dancer2::Core::HTTP;
6
7 subtest "HTTP status" => sub {
8 is( Dancer2::Core::HTTP->status( $_->{status} ) => $_->{expected},
9 'status: '. ( $_->{status} || 'undef' ) )
10 for { status => undef, expected => undef },
11 { status => 200, expected => 200 },
12 { status => 'Not Found', expected => 404 },
13 { status => 'bad_request', expected => 400 },
14 { status => 'i_m_a_teapot', expected => 418 },
15 { status => 'error', expected => 500 },
16 { status => 911, expected => 911 };
17 };
18
19
20 subtest "HTTP status_message" => sub {
21 is( Dancer2::Core::HTTP->status_message( $_->{status} ) => $_->{expected},
22 'status: '. ( $_->{status} || 'undef' ) )
23 for { status => undef, expected => undef },
24 { status => 200, expected => 'OK' },
25 { status => 'error', expected => 'Internal Server Error' },
26 { status => 911, expected => undef };
27 };
28
29 is { Dancer2::Core::HTTP->status_mapping }->{"I'm a teapot"}
30 => 418, 'status_mapping';
31
32 is { Dancer2::Core::HTTP->code_mapping }->{418}
33 => "I'm a teapot", 'code_mapping';
34
35 subtest 'all_mappings' => sub {
36 my %mappings = Dancer2::Core::HTTP->all_mappings;
37
38 is $mappings{"I'm a teapot"} => 418;
39 is $mappings{"i_m_a_teapot"} => 418;
40 is $mappings{418} => "I'm a teapot";
41 };