summaryrefslogtreecommitdiff
path: root/cpan/JSON-PP/t/115_tie_ixhash.t
blob: 51b3a4f79b8d2046fdc7e45a04c03ee9282bd390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

use strict;
use Test::More;
BEGIN { plan tests => 2 };

BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }

use JSON::PP;

# from https://rt.cpan.org/Ticket/Display.html?id=25162

SKIP: {
    eval {require Tie::IxHash};
    skip "Can't load Tie::IxHash.", 2 if ($@);

    my %columns;
    tie %columns, 'Tie::IxHash';

    %columns = (
    id => 'int',
    1 => 'a',
    2 => 'b',
    3 => 'c',
    4 => 'd',
    5 => 'e',
    );

    my $json = JSON::PP->new;

    my $js = $json->encode(\%columns);
    is( $js, q/{"id":"int","1":"a","2":"b","3":"c","4":"d","5":"e"}/ );

    $js = $json->pretty->encode(\%columns);
    is( $js, <<'STR' );
{
   "id" : "int",
   "1" : "a",
   "2" : "b",
   "3" : "c",
   "4" : "d",
   "5" : "e"
}
STR

}