Changeset 22577 for t

Show
Ignore:
Timestamp:
10/11/08 12:40:53 (6 weeks ago)
Author:
masak
Message:

[t/spec/S03-operators/autoincrement.t] added tests for overriding succ and pred

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • t/spec/S03-operators/autoincrement.t

    r22102 r22577  
    55# originally from Perl 5, by way of t/operators/auto.t 
    66 
    7 plan 47; 
     7plan 51; 
    88 
    99#L<S03/Autoincrement precedence> 
     
    120120    is $y, 1, 'Can autoincrement an undef variable (postfix)'; 
    121121} 
     122 
     123{ 
     124    class Incrementor { 
     125        has $.value; 
     126 
     127        method succ() { 
     128            $.value += 42; 
     129        } 
     130    } 
     131 
     132    my $o = Incrementor.new( value => 0 ); 
     133    $o++; 
     134    is $o.value, 42, 'Overriding succ catches postfix increment'; 
     135    ++$o; 
     136    is $o.value, 84, 'Overriding succ catches prefix increment'; 
     137} 
     138 
     139{ 
     140    class Decrementor { 
     141        has $.value; 
     142 
     143        method pred() { 
     144            $.value -= 42; 
     145        } 
     146    } 
     147 
     148    my $o = Decrementor.new( value => 100 ); 
     149    $o--; 
     150    is $o.value, 58, 'Overriding pred catches postfix decrement'; 
     151    --$o; 
     152    is $o.value, 16, 'Overriding pred catches prefix decrement'; 
     153}