Commit 31e3b928f34c8eacf5f38e88da5b588024a55113
- Diff rendering mode:
- inline
- side by side
t/Syntax.nqp
(26 / 13)
|   | |||
| 1 | 1 | #! parrot-nqp | |
| 2 | # Copyright 2009-2010, Austin Hastings. See accompanying LICENSE file, or | ||
| 2 | # Copyright 2009-2010, Austin Hastings. See accompanying LICENSE file, or | ||
| 3 | 3 | # http://www.opensource.org/licenses/artistic-license-2.0.php for license. | |
| 4 | 4 | ||
| 5 | 5 | INIT { | |
| … | … | ||
| 14 | 14 | is UnitTest::Testcase ; | |
| 15 | 15 | ||
| 16 | 16 | INIT { | |
| 17 | use( 'UnitTest::Testcase' ); | ||
| 17 | use( 'UnitTest::Testcase' ); | ||
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | 20 | MAIN(); | |
| … | … | ||
| 27 | 27 | method test_last() { | |
| 28 | 28 | my @a := <a b c d e f>; | |
| 29 | 29 | my $x; | |
| 30 | |||
| 30 | |||
| 31 | 31 | for @a { | |
| 32 | 32 | $x := ~$_; | |
| 33 | |||
| 33 | |||
| 34 | 34 | if $_ eq 'c' { | |
| 35 | 35 | last(); | |
| 36 | 36 | } | |
| 37 | 37 | } | |
| 38 | |||
| 38 | |||
| 39 | 39 | fail_unless($x eq 'c', 'Last should leave $x = c'); | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | method test_next() { | |
| 43 | 43 | my @a := <a b c d e f>; | |
| 44 | 44 | my $x := 0; | |
| 45 | |||
| 45 | |||
| 46 | 46 | for @a { | |
| 47 | 47 | if $_ ne 'g' { | |
| 48 | 48 | next(); | |
| 49 | 49 | } | |
| 50 | |||
| 50 | |||
| 51 | 51 | $x++; | |
| 52 | 52 | } | |
| 53 | |||
| 53 | |||
| 54 | 54 | fail_unless($x == 0, 'Next should keep x from incrementint'); | |
| 55 | 55 | } | |
| 56 | 56 | ||
| … | … | ||
| 58 | 58 | my @a := <a b c d e f>; | |
| 59 | 59 | my $x := 0; | |
| 60 | 60 | my $i := 0; | |
| 61 | |||
| 61 | |||
| 62 | 62 | for @a { | |
| 63 | 63 | $x++; | |
| 64 | 64 | $i++; | |
| 65 | |||
| 65 | |||
| 66 | 66 | if $i < 3 { | |
| 67 | 67 | redo(); | |
| 68 | 68 | } | |
| 69 | |||
| 69 | |||
| 70 | 70 | $i := 0; | |
| 71 | 71 | } | |
| 72 | |||
| 72 | |||
| 73 | 73 | fail_unless($x == 3 * @a, 'Redo should loop inside for'); | |
| 74 | 74 | } | |
| 75 | 75 | ||
| … | … | ||
| 77 | 77 | method m1() { | |
| 78 | 78 | 'C1'; | |
| 79 | 79 | } | |
| 80 | |||
| 81 | method m3() { | ||
| 82 | 'C1'; | ||
| 83 | } | ||
| 80 | 84 | } | |
| 81 | 85 | ||
| 82 | 86 | class C2 is C1 { | |
| 83 | 87 | method m2() { | |
| 84 | 88 | 'C2'; | |
| 85 | 89 | } | |
| 90 | |||
| 91 | method m3() { | ||
| 92 | super(); | ||
| 93 | } | ||
| 86 | 94 | } | |
| 87 | 95 | ||
| 88 | 96 | class C3 is C2 { | |
| 89 | 97 | method m1() { | |
| 90 | 98 | 'C3'; | |
| 91 | 99 | } | |
| 92 | |||
| 100 | |||
| 93 | 101 | method m2() { | |
| 94 | 102 | super(); | |
| 95 | 103 | } | |
| 104 | |||
| 105 | method m3() { | ||
| 106 | super(); | ||
| 107 | } | ||
| 96 | 108 | } | |
| 97 | 109 | ||
| 98 | 110 | method test_super() { | |
| 99 | 111 | my $obj := C3.new; | |
| 100 | 112 | fail_unless($obj.m2 eq 'C2', 'Super should call C2::m2'); | |
| 113 | fail_unless($obj.m3 eq 'C1', 'Super should call C1::m3'); | ||
| 101 | 114 | } |

