File: 107_allow_singlequote.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 (31 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download
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

use Test::More tests => 10;
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'}")

eval q| $json->decode(qq[{"foo":'"ba\'r"}]) |;
ok($@, "error $@");

$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');

is($json->decode(q|{'foo baz':'ba\'r'}|)->{"foo baz"}, q[ba'r]);

# 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));