This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[Merge] Constants, inlined subs, TARGs, ...
[perl5.git] / cpan / JSON-PP / t / 104_sortby.t
CommitLineData
d5424315
DG
1
2use Test::More;
3use strict;
4BEGIN { plan tests => 3 };
5BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
6use JSON::PP;
7#########################
8
9my ($js,$obj);
10my $pc = JSON::PP->new;
11
12$obj = {a=>1, b=>2, c=>3, d=>4, e=>5, f=>6, g=>7, h=>8, i=>9};
13
14$js = $pc->sort_by(1)->encode($obj);
15is($js, q|{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9}|);
16
17
18$js = $pc->sort_by(sub { $JSON::PP::a cmp $JSON::PP::b })->encode($obj);
19is($js, q|{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9}|);
20
21$js = $pc->sort_by('hoge')->encode($obj);
22is($js, q|{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9}|);
23
24sub JSON::PP::hoge { $JSON::PP::a cmp $JSON::PP::b }