xref: /openbsd-src/gnu/usr.bin/perl/cpan/JSON-PP/t/020_faihu.t (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1# copied over from JSON::XS and modified to use JSON::PP
2
3# adapted from a test by Aristotle Pagaltzis (http://intertwingly.net/blog/2007/11/15/Astral-Plane-Characters-in-Json)
4
5use strict;
6use warnings;
7
8BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
9
10use JSON::PP;
11use Encode qw(encode decode);
12
13use Test::More tests => 3;
14
15my ($faihu, $faihu_json, $roundtrip, $js) = "\x{10346}";
16
17$js = JSON::PP->new->allow_nonref->ascii;
18$faihu_json = $js->encode($faihu);
19$roundtrip = $js->decode($faihu_json);
20is ($roundtrip, $faihu, 'JSON in ASCII roundtrips correctly');
21
22$js = JSON::PP->new->allow_nonref->utf8;
23$faihu_json = $js->encode ($faihu);
24$roundtrip = $js->decode ($faihu_json);
25is ($roundtrip, $faihu, 'JSON in UTF-8 roundtrips correctly');
26
27$js = JSON::PP->new->allow_nonref;
28$faihu_json = encode 'UTF-16BE', $js->encode ($faihu);
29$roundtrip = $js->decode( decode 'UTF-16BE', $faihu_json);
30is ($roundtrip, $faihu, 'JSON with external recoding roundtrips correctly' );
31