tagged release 0.6.4
[parrot.git] / t / op / basic.t
blobb76b1b2541ddbd0f32313e0dca691c2d2c3bc422
1 #!perl
2 # Copyright (C) 2001-2007, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 23;
11 =head1 NAME
13 t/op/basic.t - Basic Ops
15 =head1 SYNOPSIS
17         % prove t/op/basic.t
19 =head1 DESCRIPTION
21 Tests basic string and branching operations.
23 =cut
25 # It would be very embarrassing if these didnt work...
26 pasm_output_is( <<'CODE', '', "noop, end" );
27         noop
28         end
29 CODE
31 pasm_output_is( <<'CODE', '1', "print 1" );
32         print   1
33         end
34 CODE
36 pasm_output_is( <<'CODE', 'Parrot flies', "print string" );
37         print 'Parrot flies'
38         end
39 CODE
41 pasm_output_is( <<'CODE', 'Parrot flies', "print double-quoted string" );
42        print "Parrot flies"
43        end
44 CODE
46 pasm_output_is( <<'CODE', "Parrot\tflies", "print double-quoted string, tabs" );
47        print "Parrot\tflies"
48        end
49 CODE
51 pasm_output_is( <<'CODE', q('Parrot' flies), "print double-quoted string, nested single" );
52        print "'Parrot' flies"
53        end
54 CODE
56 pasm_output_is( <<'CODE', q("Parrot" flies), "print single-quoted string, nested double" );
57        print '"Parrot" flies'
58        end
59 CODE
61 pasm_output_is( <<'CODE', q(Parrot flies), "print string with embedded hex escape" );
62        print "Parrot\x20flies"
63        end
64 CODE
66 pasm_output_is( <<'CODE', q(Parrot flies), "escaped non-special" );
67        print "Parrot fl\ies"
68        end
69 CODE
71 pasm_output_is( <<'CODE', <<OUTPUT, "print string with embedded newline" );
72        print "Parrot flies\n"
73        end
74 CODE
75 Parrot flies
76 OUTPUT
78 pasm_output_is( <<'CODE', '42', "branch_ic" );
79         set     I4, 42
80         branch  HERE
81         set     I4, 1234
82 HERE:
83         print   I4
84         end
85 CODE
87 pasm_output_is( <<'CODE', '42', "branch_ic (backward)" );
88         set     I4, 42
89         branch  one
90 two:    branch  three
91         set     I4, 1234
92         add     I4, I4, I4
93 one:
94         branch  two
95 three:
96         print   I4
97         end
98 CODE
100 pasm_output_is( <<'CODE', <<'OUTPUT', "bsr_i" );
101         print   "start\n"
103         bsr     LAB1
105         print   "done\n"
106         end
108 LAB1:   print   "lab 1\n"
109         ret
110 CODE
111 start
112 lab 1
113 done
114 OUTPUT
116 pasm_output_is( <<'CODE', <<'OUTPUT', "set_addr" );
117        set_addr I1, FOO
118        jump I1
119        print "Jump failed\n"
120        end
122 FOO:   print "Jump succeeded\n"
123        end
124 CODE
125 Jump succeeded
126 OUTPUT
128 pasm_output_is( <<'CODE', <<'OUTPUT', "multiple labels" );
129      if 0,FOO
130      if 1,BAR
131      print "not "
132 FOO:
133 BAR:
134      print "ok 1\n"
135      end
136 CODE
137 ok 1
138 OUTPUT
140 pasm_output_is( <<'CODE', 32, "Predeclared opcodes" );
141      set_i_ic I0,32
142      print I0
143      end
144 CODE
146 pir_output_is( <<'CODE', <<'OUTPUT', "pir syntax with marker - is" );
148 .sub _main
149      .const string OK = "ok\n"
150      print OK
151      end
152 .end
154 CODE
156 OUTPUT
158 pir_output_isnt( <<'CODE', <<'OUTPUT', "pir syntax with marker - isnt" );
160 .sub _main
161      .const string OK = "ok\n"
162      print OK
163      end
164 .end
166 CODE
167 parrot
168 OUTPUT
170 pir_output_like( <<'CODE', <<'OUTPUT', "pir syntax with marker - like" );
172 .sub _main
173      .const string OK = "ok\n"
174      print OK
175      end
176 .end
178 CODE
179 /^\w\w\s+$/
180 OUTPUT
182 pir_output_is( <<'CODE', <<'OUTPUT', "pir syntax with function - is" );
183 .sub _main
184      .const string OK = "ok\n"
185      print OK
186      end
187 .end
189 CODE
191 OUTPUT
193 pir_output_isnt( <<'CODE', <<'OUTPUT', "pir syntax with function - isnt" );
194 .sub _main
195      .const string OK = "ok\n"
196      print OK
197      end
198 .end
200 CODE
201 nada niete
202 OUTPUT
204 pir_output_like( <<'CODE', <<'OUTPUT', "pir syntax with function - like" );
205 .sub _main
206      .const string OK = "ok 1\n"
207      print OK
208      end
209 .end
211 CODE
212 /^\w{2}\s\d\s+$/
213 OUTPUT
215 my $CODE = '
216 .sub _main
217     print "ok\n"
218     end
219 .end
221 #.namespace';    # no \n at end of file
223 pir_error_output_like( $CODE, <<'OUTPUT', "end of line handling" );
224 /unexpected/
225 OUTPUT
227 # Local Variables:
228 #   mode: cperl
229 #   cperl-indent-level: 4
230 #   fill-column: 100
231 # End:
232 # vim: expandtab shiftwidth=4: