File: 16_tied.t

package info (click to toggle)
libcpanel-json-xs-perl 4.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,872 kB
  • sloc: perl: 1,165; makefile: 8
file content (23 lines) | stat: -rw-r--r-- 464 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use Test::More tests => 4;
use Cpanel::JSON::XS;
use Tie::Hash;
use Tie::Array;

my $js = Cpanel::JSON::XS->new;

tie my %h, 'Tie::StdHash';
%h = (a => 1);
is ($js->encode (\%h), '{"a":1}');

$h{d} = 4;
$h{c} = 3;
$h{b} = 2;
# sort the keys with canonical (GH #167)
is ($js->canonical->encode (\%h), '{"a":1,"b":2,"c":3,"d":4}');

tie my @a, 'Tie::StdArray';
@a = (1, 2);
is ($js->encode (\@a), '[1,2]');

push @a, 0;
is ($js->canonical->encode (\@a), '[1,2,0]');