Commit 31e3b928f34c8eacf5f38e88da5b588024a55113

test that super() nests to multiple levels correctly
t/Syntax.nqp
(26 / 13)
  
11#! parrot-nqp
2# Copyright 2009-2010, Austin Hastings. See accompanying LICENSE file, or
2# Copyright 2009-2010, Austin Hastings. See accompanying LICENSE file, or
33# http://www.opensource.org/licenses/artistic-license-2.0.php for license.
44
55INIT {
1414 is UnitTest::Testcase ;
1515
1616INIT {
17 use( 'UnitTest::Testcase' );
17 use( 'UnitTest::Testcase' );
1818}
1919
2020MAIN();
2727method test_last() {
2828 my @a := <a b c d e f>;
2929 my $x;
30
30
3131 for @a {
3232 $x := ~$_;
33
33
3434 if $_ eq 'c' {
3535 last();
3636 }
3737 }
38
38
3939 fail_unless($x eq 'c', 'Last should leave $x = c');
4040}
4141
4242method test_next() {
4343 my @a := <a b c d e f>;
4444 my $x := 0;
45
45
4646 for @a {
4747 if $_ ne 'g' {
4848 next();
4949 }
50
50
5151 $x++;
5252 }
53
53
5454 fail_unless($x == 0, 'Next should keep x from incrementint');
5555}
5656
5858 my @a := <a b c d e f>;
5959 my $x := 0;
6060 my $i := 0;
61
61
6262 for @a {
6363 $x++;
6464 $i++;
65
65
6666 if $i < 3 {
6767 redo();
6868 }
69
69
7070 $i := 0;
7171 }
72
72
7373 fail_unless($x == 3 * @a, 'Redo should loop inside for');
7474}
7575
7777 method m1() {
7878 'C1';
7979 }
80
81 method m3() {
82 'C1';
83 }
8084}
8185
8286class C2 is C1 {
8387 method m2() {
8488 'C2';
8589 }
90
91 method m3() {
92 super();
93 }
8694}
8795
8896class C3 is C2 {
8997 method m1() {
9098 'C3';
9199 }
92
100
93101 method m2() {
94102 super();
95103 }
104
105 method m3() {
106 super();
107 }
96108}
97109
98110method test_super() {
99111 my $obj := C3.new;
100112 fail_unless($obj.m2 eq 'C2', 'Super should call C2::m2');
113 fail_unless($obj.m3 eq 'C1', 'Super should call C1::m3');
101114}