Debian Codegraph @

t/115_tie_ixhash.t

raw
1
2 use strict;
3 use warnings;
4 use Test::More;
5 BEGIN { plan tests => 2 };
6
7 BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
8
9 use JSON;
10
11 # from https://rt.cpan.org/Ticket/Display.html?id=25162
12
13 SKIP: {
14 eval {require Tie::IxHash};
15 skip "Can't load Tie::IxHash.", 2 if ($@);
16
17 my %columns;
18 tie %columns, 'Tie::IxHash';
19
20 %columns = (
21 id => 'int',
22 1 => 'a',
23 2 => 'b',
24 3 => 'c',
25 4 => 'd',
26 5 => 'e',
27 );
28
29 my $json = JSON->new;
30
31 my $js = $json->encode(\%columns);
32 is( $js, q/{"id":"int","1":"a","2":"b","3":"c","4":"d","5":"e"}/ );
33
34 $js = $json->pretty->encode(\%columns);
35 is( $js, <<'STR' );
36 {
37 "id" : "int",
38 "1" : "a",
39 "2" : "b",
40 "3" : "c",
41 "4" : "d",
42 "5" : "e"
43 }
44 STR
45
46 }
47