X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fjson.t;h=673c0a9bd0caaf5725507333eec6cfc2331ce813;hb=c6c4ff28f913e990540021611f0b4bd3b5eda494;hp=8b05bc49be35e0bec059f7e791a757d756787809;hpb=d6fb033c1dbd94c0d527ec53291af2c50a482e9d;p=catagits%2FCatalyst-Action-REST.git diff --git a/t/json.t b/t/json.t index 8b05bc4..673c0a9 100644 --- a/t/json.t +++ b/t/json.t @@ -1,34 +1,39 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More; use FindBin; use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib"); use Test::Rest; +use utf8; -use_ok 'Catalyst::Test', 'Test::Serialize'; +eval 'use JSON 2.12'; +plan skip_all => 'Install JSON 2.12 or later to run this test' if ($@); -SKIP: { - my $has_serializer = eval "require JSON::Syck"; +plan tests => 9; - skip "JSON::Syck not available", 8, unless $has_serializer; +use_ok 'Catalyst::Test', 'Test::Serialize'; - for ('text/x-json', 'application/json') { - my $t = Test::Rest->new('content_type' => $_); - my $monkey_template = { - monkey => 'likes chicken!', - }; - my $mres = request($t->get(url => '/monkey_get')); - ok( $mres->is_success, 'GET the monkey succeeded' ); - is_deeply(JSON::Syck::Load($mres->content), $monkey_template, "GET returned the right data"); +my $json = JSON->new->utf8; +# The text/x-json should throw a warning +for ('text/x-json', 'application/json') { + my $t = Test::Rest->new('content_type' => $_); + my $monkey_template = { + monkey => 'likes chicken!', + }; + my $mres = request($t->get(url => '/monkey_get')); + ok( $mres->is_success, 'GET the monkey succeeded' ); + is_deeply($json->decode($mres->content), $monkey_template, "GET returned the right data"); - my $post_data = { - 'sushi' => 'is good for monkey', - }; - my $mres_post = request($t->post(url => '/monkey_put', data => JSON::Syck::Dump($post_data))); - ok( $mres_post->is_success, "POST to the monkey succeeded"); - is_deeply($mres_post->content, "is good for monkey", "POST data matches"); - } -}; + my $post_data = { + 'sushi' => 'is good for monkey', + 'chicken' => ' 佐藤 純', + }; + my $mres_post = request($t->post(url => '/monkey_put', data => $json->encode($post_data))); + ok( $mres_post->is_success, "POST to the monkey succeeded"); + my $exp = "is good for monkey 佐藤 純"; + utf8::encode($exp); + is_deeply($mres_post->content, $exp, "POST data matches"); +} 1;