| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Pugs
Revision: 22146
Author: moritz
Date: 04 Sep 2008 09:23:49
Changes:[t] moved goto.t to spec/
Files:| ... | ...@@ -0,0 +1,79 @@ | |
| 1 | use v6; | |
| 2 | use Test; | |
| 3 | plan 13; | |
| 4 | ||
| 5 | # L<S04/"The goto statement"> | |
| 6 | ||
| 7 | =begin description | |
| 8 | ||
| 9 | Tests for the goto() builtin | |
| 10 | ||
| 11 | We have "phases" to make sure the gotos didn't run wild. | |
| 12 | ||
| 13 | =end description | |
| 14 | ||
| 15 | ||
| 16 | our $phase; | |
| 17 | ||
| 18 | sub test1_ok { return 1 } | |
| 19 | sub test1 { | |
| 20 | &test1_ok.nextwith(); | |
| 21 | return 0; | |
| 22 | } | |
| 23 | ok(test1(), "&sub.nextwith does"); | |
| 24 | is(++$phase, 1, "phase completed"); | |
| 25 | ||
| 26 | # the same, but with subs declared after the call. | |
| 27 | ||
| 28 | sub test2 { | |
| 29 | &test2_ok.nextwith(); | |
| 30 | return 0; | |
| 31 | } | |
| 32 | sub test2_ok { return 1 } | |
| 33 | ok(test2(), "&sub.nextwith does (forward reference)"); | |
| 34 | is(++$phase, 2, "phase completed"); | |
| 35 | ||
| 36 | ok(test3(), "&sub.nextwith does (real forward reference)"); | |
| 37 | sub test3 { | |
| 38 | &test3_ok.nextwith(); | |
| 39 | return 0; | |
| 40 | } | |
| 41 | sub test3_ok { 1 } | |
| 42 | is(++$phase, 3, "phase completed"); | |
| 43 | ||
| 44 | is(moose(), $?LINE, "regular call to moose() is consistent"); | |
| 45 | is(foo(), $?LINE, "goto eliminates call stack frames"); | |
| 46 | ||
| 47 | sub foo { | |
| 48 | &moose.nextwith(); | |
| 49 | } | |
| 50 | ||
| 51 | sub moose { | |
| 52 | $?CALLER::LINE; | |
| 53 | } | |
| 54 | ||
| 55 | is(++$phase, 4, "phase completed"); | |
| 56 | ||
| 57 | # Simple test case to get support for goto LABEL in pugs | |
| 58 | # Source for the syntax: S06 "The leave function" | |
| 59 | # > last COUNT; | |
| 60 | ||
| 61 | our $test5 = 1; | |
| 62 | eval q{ goto SKIP5; }; | |
| 63 | $test5 = 0; | |
| 64 | SKIP5: | |
| 65 | is($test5, 1, "goto label", :todo<feature>); | |
| 66 | ||
| 67 | is(++$phase, 5, "phase completed"); | |
| 68 | ||
| 69 | # this one tests "goto EXPR" syntax. pugs treats "last EXPR" as "last;" in r14915. | |
| 70 | ||
| 71 | our $test6 = 1; | |
| 72 | eval q{ goto 'SK' ~ 'IP6'; }; | |
| 73 | $test6 = 0; | |
| 74 | SKIP6: | |
| 75 | is($test6, 1, "goto expr", :todo<feature>); | |
| 76 | ||
| 77 | is(++$phase, 6, "phase completed"); | |
| 78 | ||
| 79 | # vim: ft=perl6 |
| ... | ...@@ -1,79 +0,0 @@ | |
| 1 | use v6; | |
| 2 | use Test; | |
| 3 | plan 13; | |
| 4 | ||
| 5 | # L<S04/"The goto statement"> | |
| 6 | ||
| 7 | =begin description | |
| 8 | ||
| 9 | Tests for the goto() builtin | |
| 10 | ||
| 11 | We have "phases" to make sure the gotos didn't run wild. | |
| 12 | ||
| 13 | =end description | |
| 14 | ||
| 15 | ||
| 16 | our $phase; | |
| 17 | ||
| 18 | sub test1_ok { return 1 } | |
| 19 | sub test1 { | |
| 20 | &test1_ok.nextwith(); | |
| 21 | return 0; | |
| 22 | } | |
| 23 | ok(test1(), "&sub.nextwith does"); | |
| 24 | is(++$phase, 1, "phase completed"); | |
| 25 | ||
| 26 | # the same, but with subs declared after the call. | |
| 27 | ||
| 28 | sub test2 { | |
| 29 | &test2_ok.nextwith(); | |
| 30 | return 0; | |
| 31 | } | |
| 32 | sub test2_ok { return 1 } | |
| 33 | ok(test2(), "&sub.nextwith does (forward reference)"); | |
| 34 | is(++$phase, 2, "phase completed"); | |
| 35 | ||
| 36 | ok(test3(), "&sub.nextwith does (real forward reference)"); | |
| 37 | sub test3 { | |
| 38 | &test3_ok.nextwith(); | |
| 39 | return 0; | |
| 40 | } | |
| 41 | sub test3_ok { 1 } | |
| 42 | is(++$phase, 3, "phase completed"); | |
| 43 | ||
| 44 | is(moose(), $?LINE, "regular call to moose() is consistent"); | |
| 45 | is(foo(), $?LINE, "goto eliminates call stack frames"); | |
| 46 | ||
| 47 | sub foo { | |
| 48 | &moose.nextwith(); | |
| 49 | } | |
| 50 | ||
| 51 | sub moose { | |
| 52 | $?CALLER::LINE; | |
| 53 | } | |
| 54 | ||
| 55 | is(++$phase, 4, "phase completed"); | |
| 56 | ||
| 57 | # Simple test case to get support for goto LABEL in pugs | |
| 58 | # Source for the syntax: S06 "The leave function" | |
| 59 | # > last COUNT; | |
| 60 | ||
| 61 | our $test5 = 1; | |
| 62 | eval q{ goto SKIP5; }; | |
| 63 | $test5 = 0; | |
| 64 | SKIP5: | |
| 65 | is($test5, 1, "goto label", :todo<feature>); | |
| 66 | ||
| 67 | is(++$phase, 5, "phase completed"); | |
| 68 | ||
| 69 | # this one tests "goto EXPR" syntax. pugs treats "last EXPR" as "last;" in r14915. | |
| 70 | ||
| 71 | our $test6 = 1; | |
| 72 | eval q{ goto 'SK' ~ 'IP6'; }; | |
| 73 | $test6 = 0; | |
| 74 | SKIP6: | |
| 75 | is($test6, 1, "goto expr", :todo<feature>); | |
| 76 | ||
| 77 | is(++$phase, 6, "phase completed"); | |
| 78 | ||
| 79 | # vim: ft=perl6 |