Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[t] moved sub_parameter_traits to spec/

git-svn-id: http://svn.pugscode.org/pugs@22126 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit 4ae127ae0adca6048178c5422ea5ec5e83eff885 1 parent dd2b31b
moritz authored
Showing with 58 additions and 0 deletions.
  1. +58 −0 S06-traits/misc.t
View
58 S06-traits/misc.t
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.