-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[t] moved sub_parameter_traits to spec/
git-svn-id: http://svn.pugscode.org/pugs@22126 c213334d-75ef-0310-aa23-eaa082d1ae64
- Loading branch information
moritz
committed
Sep 3, 2008
1 parent
dd2b31b
commit 4ae127a
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use v6; | ||
|
||
use Test; | ||
|
||
plan 12; | ||
|
||
=begin description | ||
Testing parameter traits for subroutines | ||
L<S06/"Parameter traits"> | ||
=end description | ||
|
||
my $foo=1; | ||
|
||
# note: many of these errors can be detected at compile time, so need | ||
# eval_dies_ok instead of dies_ok | ||
eval_dies_ok ' | ||
sub mods_param ($x) { $x++; } | ||
mods_param($foo) | ||
', | ||
'can\'t modify parameter, constant by default'; | ||
|
||
|
||
# is readonly | ||
eval_dies_ok 'sub mods_param_constant ($x is readonly) { $x++; }; | ||
mods_param_constant($foo);' , | ||
'can\'t modify constant parameter, constant by default'; | ||
|
||
sub mods_param_rw ($x is rw) { $x++; } | ||
dies_ok { mods_param_rw(1) }, 'can\'t modify constant even if we claim it\'s rw'; | ||
sub mods_param_rw_does_nothing ($x is rw) { $x; } | ||
lives_ok { mods_param_rw_does_nothing(1) }, 'is rw with non-lvalue should autovivify'; | ||
|
||
lives_ok { mods_param_rw($foo) }, 'pass by "is rw" doesn\'t die'; | ||
is($foo, 2, 'pass by reference works'); | ||
|
||
#icopy | ||
$foo=1; | ||
sub mods_param_copy ($x is copy) {$x++;} | ||
lives_ok { mods_param_copy($foo) }, 'is copy'; | ||
is($foo, 1, 'pass by value works'); | ||
|
||
# is ref | ||
$foo=1; | ||
sub mods_param_ref ($x is ref) { $x++; } | ||
dies_ok { mods_param_ref(1); }, 'is ref with non-lvalue'; | ||
lives_ok { mods_param_ref($foo); }, 'is ref with non-lvalue', :todo; | ||
is($foo, 2, 'is ref works', :todo); | ||
|
||
# is context | ||
# Doesn't even compile, which is lucky, because I don't understand it well | ||
# enough to write an actual test... | ||
ok(eval('sub my_format (*@data is context(Item)) { }; 1'), "is context - compile check"); | ||
|
||
# To do - check that is context actually works | ||
# vim: ft=perl6 |