[TT# 1592][t] Improve test for open opcode delegation. All tests in the file pass...
[parrot.git] / t / op / basic.t
blob92935b74c6418315af62d1d92a155c50e1f49d67
1 #!perl
2 # Copyright (C) 2001-2007, Parrot 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', "local_branch_c_i" );
101         print    "start\n"
103         new P0, 'ResizableIntegerArray'
105         local_branch P0, LAB1
107         print    "done\n"
108         end
110 LAB1:   print    "lab 1\n"
111         local_return P0
112 CODE
113 start
114 lab 1
115 done
116 OUTPUT
118 pasm_output_is( <<'CODE', <<'OUTPUT', "set_addr" );
119        set_addr I1, FOO
120        jump I1
121        print "Jump failed\n"
122        end
124 FOO:   print "Jump succeeded\n"
125        end
126 CODE
127 Jump succeeded
128 OUTPUT
130 pasm_output_is( <<'CODE', <<'OUTPUT', "multiple labels" );
131      if 0,FOO
132      if 1,BAR
133      print "not "
134 FOO:
135 BAR:
136      print "ok 1\n"
137      end
138 CODE
139 ok 1
140 OUTPUT
142 pasm_output_is( <<'CODE', 32, "Predeclared opcodes" );
143      set_i_ic I0,32
144      print I0
145      end
146 CODE
148 pir_output_is( <<'CODE', <<'OUTPUT', "pir syntax with marker - is" );
150 .sub _main
151      .const string OK = "ok\n"
152      print OK
153      end
154 .end
156 CODE
158 OUTPUT
160 pir_output_isnt( <<'CODE', <<'OUTPUT', "pir syntax with marker - isnt" );
162 .sub _main
163      .const string OK = "ok\n"
164      print OK
165      end
166 .end
168 CODE
169 parrot
170 OUTPUT
172 pir_output_like( <<'CODE', <<'OUTPUT', "pir syntax with marker - like" );
174 .sub _main
175      .const string OK = "ok\n"
176      print OK
177      end
178 .end
180 CODE
181 /^\w\w\s+$/
182 OUTPUT
184 pir_output_is( <<'CODE', <<'OUTPUT', "pir syntax with function - is" );
185 .sub _main
186      .const string OK = "ok\n"
187      print OK
188      end
189 .end
191 CODE
193 OUTPUT
195 pir_output_isnt( <<'CODE', <<'OUTPUT', "pir syntax with function - isnt" );
196 .sub _main
197      .const string OK = "ok\n"
198      print OK
199      end
200 .end
202 CODE
203 nada niete
204 OUTPUT
206 pir_output_like( <<'CODE', <<'OUTPUT', "pir syntax with function - like" );
207 .sub _main
208      .const string OK = "ok 1\n"
209      print OK
210      end
211 .end
213 CODE
214 /^\w{2}\s\d\s+$/
215 OUTPUT
217 my $CODE = '
218 .sub _main
219     print "ok\n"
220     end
221 .end
223 #.namespace';    # no \n at end of file
225 pir_error_output_like( $CODE, <<'OUTPUT', "end of line handling" );
226 /unexpected/
227 OUTPUT
229 # Local Variables:
230 #   mode: cperl
231 #   cperl-indent-level: 4
232 #   fill-column: 100
233 # End:
234 # vim: expandtab shiftwidth=4: