drop the use of fatal warnings in tests
[p5sagit/JSON-MaybeXS.git] / t / legacy.t
CommitLineData
ebf1e433 1use strict;
4e1fb2f8 2use warnings;
ebf1e433 3
4use Test::Without::Module 'Cpanel::JSON::XS';
5use Test::More;
6use JSON::MaybeXS qw/:legacy/;
7
ebf1e433 8my $in = '[1, 2, 3, 4]';
9
ebf1e433 10my $arr = from_json($in);
11my $j = to_json($arr);
12is($j, '[1,2,3,4]');
13is(ref($arr), 'ARRAY');
14
c397f194 15my $json = 'JSON::MaybeXS';
16diag "using invocant: $json";
17like(
18 do { eval { $json->from_json($in) }; $@ },
19 qr/from_json should not be called as a method/,
20 'blessed invocant detected in from_json',
21);
22
23like(
24 do { eval { $json->to_json($arr, { blah => 1 } ) }; $@ },
25 qr/to_json should not be called as a method/,
26 'blessed invocant detected in to_json',
27);
28
ebf1e433 29done_testing;
30
31__END__
32
33 to_json
34 $json_text = to_json($perl_scalar)
35
36 Converts the given Perl data structure to a json string.
37
38 This function call is functionally identical to:
39
40 $json_text = JSON->new->encode($perl_scalar)
41
42 from_json
43 $perl_scalar = from_json($json_text)
44
45 The opposite of "to_json": expects a json string and tries to parse it,
46 returning the resulting reference.
47
48 This function call is functionally identical to:
49
50 $perl_scalar = JSON->decode($json_text)