Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f244f315cb
Fetching contributors…

Cannot retrieve contributors at this time

file 49 lines (36 sloc) 1.357 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
use v6;

use Test;

# L<S04/Other C<do>-like forms/lazy>

plan 12;

{
  my $was_in_lazy;

  my $var := LAZY { $was_in_lazy++; 42 };

  ok !$was_in_lazy, 'our lazy block wasn\'t yet executed (1)';

  is $var, 42, 'our lazy var has the correct value';
  ok $was_in_lazy, 'our lazy block was executed';

  is $var, 42, 'our lazy var still has the correct value';
  is $was_in_lazy, 1, 'our lazy block was not executed again';
}

# dies_ok/lives_ok tests:
{
  my $was_in_lazy;
  my $lazy := LAZY { $was_in_lazy++; 42 };
  lives_ok { $lazy = 23 }, "reassigning our var containing a lazy worked (1)";
  is $lazy, 23, "reassigning our var containing a lazy worked (2)";
  ok !$was_in_lazy, "reassigning our var containing a lazy worked (3)";
}

{
  my $was_in_lazy;
  my $lazy := LAZY { $was_in_lazy++; 42 };
  lives_ok { $lazy := 23 }, "rebinding our var containing a lazy worked (1)";
  is $lazy, 23, "rebinding our var containing a lazy worked (2)";
  ok !$was_in_lazy, "rebinding our var containing a lazy worked (3)";
}

#?rakudo todo 'why ever not?'
{
  dies_ok { (LAZY { 42 }) = 23 },
    "directly assigning to a lazy var does not work";
}

# Arguably, we should remove the $was_in_lazy tests, as it doesn't really
# matter when the lazy {...} block is actually executed.

# vim: ft=perl6
Something went wrong with that request. Please try again.