tagged release 0.7.1
[parrot.git] / t / library / hllmacros.t
blob0ba8340334ff2b5bbb95d98b33368f07b2517769
1 #! parrot
2 # Copyright (C) 2008, The Perl Foundation.
3 # $Id$
5 .include 'include/hllmacros.pir'
6 .sub main :main
7     .include 'include/test_more.pir'
9     plan(17)
11     ok(1, 'included .hll macros definitions')
13     ok(1, 'before embedded newline') .NL() ok(1, 'after embedded newline')
15     $I0 = 0
16     $I1 = 1
17     .If($I0 != $I1, {
18       ok (1, '.If with true condition')
19     })
20     .If($I0 == $I1, {
21       ok (0, '.If with false condition')
22     })
24     .Unless($I0 == $I1, {
25       ok (1, '.Unless with false condition')
26     })
27     .Unless($I0 != $I1, {
28       ok (0, '.Unless with true condition')
29     })
31     .IfElse($I0 != $I1, {
32       ok (1, '.IfElse, true if')
33     }, {
34       ok (0, '.IfElse, true else')
35     })
36     .IfElse($I0 == $I1, {
37       ok (0, '.IfElse, false if')
38     }, {
39       ok (1, '.IfElse, false else')
40     })
41   
42     $I2 = 0
43     .While( $I2<10, {
44       inc $I2
45     })
46     .IfElse($I2 == 10, {
47       ok (1, '.While doing something')
48     }, {
49       ok (0, '.While doing something')
50     }) 
52     .While( 1==0, {
53       ok (0, 'while body should never happen')
54     })
56     $I2 = 0
57     .DoWhile({
58       ok (1, '.DoWhile doing something when the condition is false')
59     }, $I2)
61     $I2 = 0
62     .DoWhile({
63       inc $I2
64     }, $I2<10)
65     .IfElse($I2 == 10, {
66       ok (1, '.DoWhile doing something')
67     }, {
68       ok (0, '.DoWhile doing something')
69     }) 
71     $I2 = 0
72     .Loop({
73         .IfElse($I2==10,{
74             goto loop_done  
75         }, {
76             inc $I2
77         })
78     })
79 loop_done:
80     .IfElse($I2 == 10, {
81         ok (1, '.Loop worked')
82     }, {
83         ok (0, '.Loop failed')
84     })
86     .For({
87         $I2 = 0
88         $I3 = 0
89         ok (1, 'initial condition')
90     }, $I2 < 3, {
91         inc $I2
92     }, {
93         inc $I3
94     })
95     .IfElse($I2 == 3, {
96         ok (1, '.For continue worked')
97     }, {
98         ok (0, '.For continue failed')
99     })
100     .IfElse($I3 == 3, {
101         ok (1, '.For body worked')
102     }, {
103         ok (0, '.For body failed')
104     })
106     $P1 = new 'ResizablePMCArray'
107     push $P1, 'one'
108     push $P1, 'two'
109     push $P1, 'three'
111     .Foreach($S0, $P1, {
112       $S1 = '.Foreach' . $S0
113       ok(1, $S1)
114     })
116 .end
118 # Local Variables:
119 #   mode: pir
120 #   fill-column: 100
121 # End:
122 # vim: expandtab shiftwidth=4 ft=pir: