|
|
Author: pmichaud
Date: Sat Aug 18 00:32:07 2007
New Revision: 20668
Modified:
trunk/languages/nqp/t/09-var.t
Log:
[nqp]:
* Add more tests for my/our variables in blocks.
* Patch courtesy Colin Kuskie <ckuskie@xxxxxxxxxxxx> (perlDreamer++)
* (The previous r0667 commit is also from Colin; I hit 'commit'
before crediting him properly there, so I'm doing it here: perlDreamer++ )
Modified: trunk/languages/nqp/t/09-var.t
==============================================================================
--- trunk/languages/nqp/t/09-var.t (original)
+++ trunk/languages/nqp/t/09-var.t Sat Aug 18 00:32:07 2007
@@ -1,8 +1,70 @@
#!./parrot
-say '1..2';
+say('1..13');
-my $o1 := 'ok 1'; say($o1);
+my $o1 := 'ok 1'; print($o1); say(" # direct binding and scoping");
-my $o2; $o2 := 'ok 2'; say($o2);
+my $o2; $o2 := 'ok 2'; print($o2); say(" # first scope and declare, then
bind");
+my $o3 := 'ok 3';
+my $p3 := $o3;
+print($p3); say(" # bind to another variable");
+
+$o3 := 'ok 4';
+print($o3); say(" # rebind the original, the bound one does not change");
+
+my $r1 := 'not ok 5';
+my $r2 := 'ok 5';
+my $r3;
+$r3 := $r1;
+$r3 := $r2;
+print($r3); say(' # variables can be rebound');
+
+my $b1 := 'ok 7';
+
+{
+ my $b1 := 'ok 6';
+ print($b1); say(' # my scoping works inside a block');
+}
+
+print($b1); say(' # block does not stomp on out scope');
+
+my $b2 := 'ok 8';
+
+{
+ print($b2); say(' # variables scoped outside of block persists inside the
block');
+}
+
+my $b3;
+{
+ my $b4 := 'ok 9';
+ $b3 := $b4;
+}
+print($b3); say(' # variable is bound to the value, not the symbol in the
block');
+
+{
+ my $b5 := 'not ';
+}
+print($b5);say('ok 10 # $b5, defined inside block, does not exist outside');
+
+{
+ our $m1 := 'ok 11 ';
+}
+
+unless $m1 {
+ print('not ');
+}
+say('ok 11 # our variables have package scope, exists outside of block');
+
+our $m2;
+$m2 := 'ok 12';
+{
+ print($m2); say(' # our variables exist inside blocks');
+}
+
+our $m3;
+$m3 := 'not ok 13';
+{
+ $m3 := 'ok 13';
+}
+print($m3); say(' # our variables written inside block keep their values
outside');
|
|