File: 17_relaxed.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-- 956 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 $] < 5.008 ? (skip_all => "5.6") : (tests => 13);
use Cpanel::JSON::XS;

my $json = Cpanel::JSON::XS->new->relaxed;

is (encode_json ($json->decode (' [1,2, 3]')), '[1,2,3]');
is (encode_json ($json->decode ('[1,2, 4 , ]')), '[1,2,4]');
ok (!eval { $json->decode ('[1,2, 3,4,,]') });
ok (!eval { $json->decode ('[,1]') });

is (encode_json ($json->decode (' {"1":2}')), '{"1":2}' );
is (encode_json ($json->decode ('{"1":2,}')), '{"1":2}');
is (encode_json ($json->decode (q({'1':2}))), '{"1":2}'); # allow_singlequotes
is (encode_json ($json->decode ('{a:2}')),    '{"a":2}'); # allow_barekey
ok (!eval { $json->decode ('{,}') });

is (encode_json ($json->decode ("[1#,2\n ,2,#  ]  \n\t]")), '[1,2]');

is (encode_json ($json->decode ("[\"Hello\tWorld\"]")), '["Hello\tWorld"]');

is (encode_json ($json->decode ('{"a b":2}')),    '{"a b":2}'); # allow_barekey

is (encode_json ($json->decode ('["ha"] #ouch')), '["ha"]'); # allow comments