Last active
December 18, 2015 10:49
-
-
Save ysasaki/5771505 to your computer and use it in GitHub Desktop.
return と return undef の違いを説明するときに使用したコード。list contextの場合に挙動が異なる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; | |
use strict; | |
use warnings; | |
use Test::More; | |
use Test::Name::FromLine; | |
sub return_only { return } | |
sub return_undef { return undef } | |
subtest 'scalar context' => sub { | |
my $only = return_only(); | |
is $only, undef; | |
my $undef = return_undef(); | |
is $undef, undef; | |
}; | |
subtest 'list context' => sub { | |
my @only = return_only(); | |
is_deeply \@only, []; | |
my @undef = return_undef(); | |
is_deeply \@undef, [undef]; | |
}; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment