Skip to content

Commit

Permalink
[t/spec] Nope, can't assign to a constant, even if it doesn't change it.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.pugscode.org/pugs@27602 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
kyle committed Jul 17, 2009
1 parent e96008a commit 7e6f02d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions S04-declarations/constant.t
Expand Up @@ -216,28 +216,27 @@ plan 33;
is con, 64522, 'constant-returning sub after ++ has not changed';
}

# XXX identities (spec?)
#?rakudo todo 'unspecced?'
# identities -- can't assign to constant even if it doesn't change it.
{
constant $change = 'alteration';

lives_ok { $change ~= '' }, 'can append nothing to a constant';
lives_ok { $change = 'alteration' }, 'can assign constant its own value';
dies_ok { $change ~= '' }, 'append nothing to a constant';
dies_ok { $change = 'alteration' }, 'assign constant its own value';
my $t = $change;
lives_ok { $change = $t }, 'can assign constant its own value from var';
lives_ok { $change = 'alter' ~ 'ation' },
'can assign constant its own value from expression';
dies_ok { $change = $t }, 'assign constant its own value from var';
dies_ok { $change = 'alter' ~ 'ation' },
'assign constant its own value from expression';

constant $five = 5;

lives_ok { $five += 0 }, 'can add zero to constant number';
lives_ok { $five *= 1 }, 'can multiply constant number by 1';
lives_ok { $five = 5 }, 'can assign constant its own value';
dies_ok { $five += 0 }, 'add zero to constant number';
dies_ok { $five *= 1 }, 'multiply constant number by 1';
dies_ok { $five = 5 }, 'assign constant its own value';
my $faux_five = $five;
lives_ok { $five = $faux_five },
'can assign constant its own value from variable';
lives_ok { $five = 2 + 3 },
'can assign constant its own value from expression';
dies_ok { $five = $faux_five },
'assign constant its own value from variable';
dies_ok { $five = 2 + 3 },
'assign constant its own value from expression';
}

# vim: ft=perl6

0 comments on commit 7e6f02d

Please sign in to comment.