1 | use Test::More; |
1 | use Test::More; |
2 | |
2 | |
3 | # copied over from JSON::PC and modified to use JSON::XS |
3 | # copied over from JSON::PC and modified to use JSON::XS |
4 | |
4 | |
5 | use strict; |
5 | use strict; |
6 | BEGIN { plan tests => 22 }; |
6 | BEGIN { plan tests => 20 }; |
7 | use JSON::XS; |
7 | use JSON::XS; |
8 | |
8 | |
9 | my ($js,$obj); |
9 | my ($js,$obj); |
10 | |
10 | |
11 | my $pc = new JSON::XS; |
11 | my $pc = new JSON::XS; |
… | |
… | |
79 | |
79 | |
80 | $js = '{"id":"}'; |
80 | $js = '{"id":"}'; |
81 | eval q{ $pc->decode($js) }; |
81 | eval q{ $pc->decode($js) }; |
82 | like($@, qr/unexpected end/i); |
82 | like($@, qr/unexpected end/i); |
83 | |
83 | |
84 | $obj = { foo => sub { "bar"; } }; |
84 | $obj = { foo => sub { "bar" } }; |
85 | eval q{ $js = $pc->encode($obj) }; |
85 | eval q{ $js = $pc->encode($obj) }; |
86 | like($@, qr/JSON can only/i, 'invalid value (coderef)'); |
86 | like($@, qr/JSON can only/i, 'invalid value (coderef)'); |
87 | |
|
|
88 | |
|
|
89 | $obj = { foo => *STDERR }; |
|
|
90 | $js = $pc->encode($obj); |
|
|
91 | is($js, '{"foo":"*main::STDERR"}', "type blog"); |
|
|
92 | |
|
|
93 | $obj = { foo => \*STDERR }; |
|
|
94 | eval q{ $js = $pc->encode($obj) }; |
|
|
95 | like($@, qr/JSON can only/i, 'invalid value (ref of type blog)'); |
|
|
96 | |
87 | |
97 | #$obj = { foo => bless {}, "Hoge" }; |
88 | #$obj = { foo => bless {}, "Hoge" }; |
98 | #eval q{ $js = $pc->encode($obj) }; |
89 | #eval q{ $js = $pc->encode($obj) }; |
99 | #like($@, qr/JSON can only/i, 'invalid value (blessd object)'); |
90 | #like($@, qr/JSON can only/i, 'invalid value (blessd object)'); |
100 | |
91 | |
101 | $obj = { foo => \$js }; |
92 | $obj = { foo => \$js }; |
102 | eval q{ $js = $pc->encode($obj) }; |
93 | eval q{ $js = $pc->encode($obj) }; |
103 | like($@, qr/JSON can only/i, 'invalid value (ref)'); |
94 | like($@, qr/cannot encode reference/i, 'invalid value (ref)'); |
104 | |
95 | |