Changeset 6376 for t/unspecced/cont.t
- Timestamp:
- 08/20/05 15:47:35 (3 years ago)
- svk:copy_cache_prev:
- 8581
- Files:
-
- 1 modified
-
t/unspecced/cont.t (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
t/unspecced/cont.t
r4600 r6376 10 10 =cut 11 11 12 plan 1 3;12 plan 14; 13 13 14 14 sub simple1() returns Int { … … 18 18 is(simple1(), 2, 'using ec instead of return'); 19 19 20 sub simple2( $n) {20 sub simple2(Num $n) { 21 21 if ($n == 5) { 22 22 &?CALLER_CONTINUATION(1); … … 35 35 is(closure1(), 5, 'closure uses ec to escape', :todo); 36 36 37 sub call_argument( $f) {38 return $f( );37 sub call_argument(Code $f, $arg) { 38 return $f($arg); 39 39 } 40 sub foo( $f) returns Int {41 call_argument($f );40 sub foo(Code $f) returns Int { 41 call_argument($f, 8); 42 42 return 3; 43 43 } 44 sub passing1 returns Int {44 sub passing1 () returns Int { 45 45 foo(&?CALLER_CONTINUATION); 46 46 return 2; 47 47 } 48 eval_is('passing1()', 8, 'ec passed as an argument', :todo);48 is(try { passing1() }, 8, 'ec passed as an argument', :todo); 49 49 50 sub is_five( $n,$f) {50 sub is_five(Num $n, Code $f) { 51 51 if ($n == 5) { 52 52 $f(1); … … 54 54 return 0; 55 55 } 56 sub passing2_not_cont( $n) {56 sub passing2_not_cont(Num $n) { 57 57 my $a = 9; 58 58 is_five($n, sub { $a = 1 }); 59 59 return $a; 60 60 } 61 sub passing2( $n) {61 sub passing2(Num $n) { 62 62 is_five($n, &?CALLER_CONTINUATION); 63 63 return 9; 64 64 } 65 sub passing2_closure( $n) {65 sub passing2_closure(Num $n) { 66 66 my $c = &?CALLER_CONTINUATION; 67 67 is_five($n, sub { $c(1) }); 68 68 return 9; 69 69 } 70 is(passing2_not_cont(5), 1, 'is_five w/o ec ');71 is(passing2_not_cont(2), 9, 'is_five w/o ec ');72 is(passing2(5), 1, 'is_five passing ec itself ', :todo);73 is(passing2(2), 9, 'is_five passing ec itself ');74 is(passing2_closure(5), 1, 'is_five passing ec via closure ', :todo);75 is(passing2_closure(2), 9, 'is_five passing ec via closure ');70 is(passing2_not_cont(5), 1, 'is_five w/o ec (1)'); 71 is(passing2_not_cont(2), 9, 'is_five w/o ec (2)'); 72 is(passing2(5), 1, 'is_five passing ec itself (1)', :todo); 73 is(passing2(2), 9, 'is_five passing ec itself (2)'); 74 is(passing2_closure(5), 1, 'is_five passing ec via closure (1)', :todo); 75 is(passing2_closure(2), 9, 'is_five passing ec via closure (2)'); 76 76 77 77 sub callconty() { … … 79 79 return 1; 80 80 } 81 sub conty( $c) {81 sub conty(Code $c) { 82 82 $c(2); 83 return 3; 83 84 } 84 85 is(callconty(), 2, 'continuation bug', :todo<bug>); … … 86 87 # Now test complicated full continuations got from the same place. 87 88 88 sub callcc (Code &block) { &block(&?CALLER_CONTINUATION) } 89 { 90 sub callcc (Code &block) { &block(&?CALLER_CONTINUATION) } 89 91 90 my $cnt;91 my $counter = 0;92 my $cont; 93 my $counter = 0; 92 94 93 callcc -> $cc { $cnt = $cc }; 94 $counter++; 95 ok 1, "$counter times through the loop"; 96 $cnt(undef) unless $counter == 3; 97 is($counter, 3, "Looping with a full continuation", :todo<feature>); 95 callcc -> $cc { $cont = $cc }; 96 $counter++; 97 $cont(undef) unless $counter == 3; 98 is($counter, 3, "Looping with a full continuation", :todo<feature>); 99 } 100 101 # Really evil: Store continuations in an aggregate 102 { 103 my %conts; 104 my $foo = sub { %conts<foo> = &?CALLER_CONTINUATION; return "normalfoo" }; 105 my $bar = sub { %conts<bar> = &?CALLER_CONTINUATION; return "normalbar" }; 106 107 my $history; 108 my $counter = 0; 109 110 $history ~= $foo(); $history ~= "foo$counter"; $counter++; 111 $history ~= $bar(); $history ~= "bar$counter"; $counter++; 112 %conts<foo>("secondfoo") if $counter <= 2; 113 %conts<bar>("secondbar") if $counter <= 4; 114 115 is 116 $history, 117 "normalfoofoo0normalbarbar1secondfoofoo2normalbarbar3secondbarbar4", 118 "continuations stored in an aggregate with loops"; 119 }
