Skip to content

Commit 40ba548

Browse files
committed
Test undef and blessed objects
just to be thorough
1 parent 1e987f1 commit 40ba548

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

t/encoding.t

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ my $model = MetaCPAN::Web::Model::API::Module->new(api => 'http://example.com');
2020
# $body
2121
# $body, $type
2222
sub get_raw {
23-
$res_body = shift.'';
23+
$res_body = shift;
2424
$content_type = shift if @_;
2525
my $res = $model->source(qw( who cares ))->recv->{raw};
2626
return $res;
@@ -58,9 +58,26 @@ foreach my $ctype ( 'text/plain', 'application/json' ){
5858
# HEAVY BLACK HEART
5959
is get_raw($filedata), "i \x{2764} metacpan", 'correct message';
6060
ok !@warnings, 'no warnings after valid UTF-8' or diag shift @warnings;
61+
62+
# not sure if we'll ever actually get undef
63+
is get_raw(undef), '', 'undef becomes blank';
64+
ok !@warnings, 'no warnings for undef' or diag shift @warnings;
65+
66+
# not sure if we'll ever actually get blessed object
67+
my $b = Blessed_String->new('holy');
68+
ok ref $b, 'blessed ref';
69+
is "$b", 'holy', 'stringifies correctly';
70+
is get_raw($b), 'holy', 'blessed string';
71+
ok !@warnings, 'no warnings for blessed obj' or diag shift @warnings;
6172
}
6273

6374
done_testing;
6475

76+
{ package # no_index
77+
Blessed_String;
78+
sub new { bless [ $_[1] ], $_[0]; }
79+
use overload '""' => sub { shift->[0] };
80+
}
81+
6582
__DATA__
6683
i ❤ metacpan

0 commit comments

Comments
 (0)