Created
July 4, 2016 22:30
-
-
Save perlpunk/1d4c4f38b3f043f63a2bbaa242bc207a to your computer and use it in GitHub Desktop.
t/deserialize.t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More; | |
use Plack::Test; | |
use HTTP::Request::Common; | |
{ | |
package App; | |
use Dancer2; | |
set serializer => 'JSON'; | |
} | |
my $app = App->to_app; | |
use utf8; | |
use JSON; | |
use Encode; | |
use Module::Runtime 'use_module'; | |
use Devel::Peek (); | |
note "Verify Serializers decode into characters"; { | |
my $utf8 = '∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i)'; | |
test_psgi $app, sub { | |
my $cb = shift; | |
# my @serializers = qw/ Dumper YAML /; FAIL | |
# my @serializers = qw/ YAML /; SUCCESS | |
my @serializers = @ARGV; | |
for my $type ( @serializers ) { | |
diag "\n--- $type ---\n"; | |
my $class = "Dancer2::Serializer::$type"; | |
use_module($class); | |
my $serializer = $class->new(); | |
my $body = $serializer->serialize({utf8 => $utf8}); | |
diag "Devel::Peek::Dump:"; | |
Devel::Peek::Dump $body; | |
warn Data::Dumper->Dump([\$body], ['body']); | |
if ($type eq 'Dumper') { | |
cmp_ok($body, '=~', qr{^\$VAR}, "Dumper should start with \$VAR"); | |
} | |
else { | |
cmp_ok($body, '=~', qr{^---}, "YAML should start with ---"); | |
} | |
# change the app serializer | |
# we're overiding a RO attribute only for this test! | |
Dancer2->runner->apps->[0]->set_serializer_engine( | |
$serializer | |
); | |
my $r = $cb->( | |
PUT '/from_params', | |
'Content-Type' => $serializer->content_type, | |
Content => $body, | |
); | |
} | |
}; | |
} | |
done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment