| 1 |
# copied over from JSON::XS and modified to use JSON |
| 2 |
|
| 3 |
# adapted from a test by Aristotle Pagaltzis (http://intertwingly.net/blog/2007/11/15/Astral-Plane-Characters-in-Json) |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; } |
| 9 |
|
| 10 |
BEGIN { if ($] < 5.008) { require Test::More; Test::More::plan(skip_all => "requires Perl 5.8 or later"); } }; |
| 11 |
|
| 12 |
use JSON; |
| 13 |
use Encode qw(encode decode); |
| 14 |
|
| 15 |
use Test::More tests => 3; |
| 16 |
|
| 17 |
my ($faihu, $faihu_json, $roundtrip, $js) = "\x{10346}"; |
| 18 |
|
| 19 |
$js = JSON->new->allow_nonref->ascii; |
| 20 |
$faihu_json = $js->encode($faihu); |
| 21 |
$roundtrip = $js->decode($faihu_json); |
| 22 |
is ($roundtrip, $faihu, 'JSON in ASCII roundtrips correctly'); |
| 23 |
|
| 24 |
$js = JSON->new->allow_nonref->utf8; |
| 25 |
$faihu_json = $js->encode ($faihu); |
| 26 |
$roundtrip = $js->decode ($faihu_json); |
| 27 |
is ($roundtrip, $faihu, 'JSON in UTF-8 roundtrips correctly'); |
| 28 |
|
| 29 |
$js = JSON->new->allow_nonref; |
| 30 |
$faihu_json = encode 'UTF-16BE', $js->encode ($faihu); |
| 31 |
$roundtrip = $js->decode( decode 'UTF-16BE', $faihu_json); |
| 32 |
is ($roundtrip, $faihu, 'JSON with external recoding roundtrips correctly' ); |