Revision: | 1.2 |
Committed: | Tue Feb 17 23:29:38 2009 UTC (15 years, 4 months ago) by root |
Content type: | application/x-troff |
Branch: | MAIN |
CVS Tags: | rel-4_0, rel-3_0, rel-4_01, rel-4_03, rel-4_02, rel-2_3, rel-4_0_00, rel-2_34, rel-2_32, rel-2_33, rel-2_31, rel-2_2311, rel-3_01, rel-3_02, rel-3_03, rel-3_04, rel-2_232, rel-2_29, rel-2_28, rel-2_25, rel-2_24, rel-2_27, rel-2_26, HEAD |
Changes since 1.1: | +1 -1 lines |
Log Message: | *** empty log message *** |
# | Content |
---|---|
1 | #! perl |
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 | 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' ); |