File: 107_allow_singlequote.t

package info (click to toggle)
libcpanel-json-xs-perl 4.09-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,776 kB
  • sloc: perl: 1,052; makefile: 8
file content (26 lines) | stat: -rw-r--r-- 870 bytes parent folder | download | duplicates (5)
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

use Test::More tests => 8;
use strict;
use Cpanel::JSON::XS;
#########################

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

eval q| $json->decode("{'foo':'bar'}") |;
ok($@, "error $@"); # in XS and PP, the error message differs.
# '"' expected, at character offset 1 (before "'foo':'bar'}")

$json->allow_singlequote;

is($json->decode(q|{'foo':"bar"}|)->{foo}, 'bar');
is($json->decode(q|{'foo':'bar'}|)->{foo}, 'bar');
is($json->allow_barekey->decode(q|{foo:'bar'}|)->{foo}, 'bar');

is($json->decode(q|{'foo baz':'bar'}|)->{"foo baz"}, 'bar');

# GH 54 from Locale::Wolowitz
is($json->decode(q|{xo:"how's it hangin 1"}|)->{"xo"}, q(how's it hangin 1));
$json->allow_barekey(0);
is($json->decode(q|{"xo":"how's it hangin 1"}|)->{"xo"}, q(how's it hangin 1));
$json->allow_singlequote(0);
is($json->decode(q|{"xo":"how's it hangin 1"}|)->{"xo"}, q(how's it hangin 1));