1 |
#! perl |
2 |
|
3 |
# adapted form 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 |
use JSON::XS; |
9 |
use Encode qw(encode decode); |
10 |
|
11 |
use Test::More tests => 3; |
12 |
|
13 |
my ($faihu, $faihu_json, $roundtrip, $js) = "\x{10346}"; |
14 |
|
15 |
$js = JSON::XS->new->allow_nonref->ascii; |
16 |
$faihu_json = $js->encode($faihu); |
17 |
$roundtrip = $js->decode($faihu_json); |
18 |
is ($roundtrip, $faihu, 'JSON in ASCII roundtrips correctly'); |
19 |
|
20 |
$js = JSON::XS->new->allow_nonref->utf8; |
21 |
$faihu_json = $js->encode ($faihu); |
22 |
$roundtrip = $js->decode ($faihu_json); |
23 |
is ($roundtrip, $faihu, 'JSON in UTF-8 roundtrips correctly'); |
24 |
|
25 |
$js = JSON::XS->new->allow_nonref; |
26 |
$faihu_json = encode 'UTF-16BE', $js->encode ($faihu); |
27 |
$roundtrip = $js->decode( decode 'UTF-16BE', $faihu_json); |
28 |
is ($roundtrip, $faihu, 'JSON with external recoding roundtrips correctly' ); |