Ticket #793: ifunless.t_to_pir.patch
File ifunless.t_to_pir.patch, 6.8 KB (added by flh, 13 years ago) |
---|
-
t/op/ifunless.t
1 #!p erl2 # Copyright (C) 2001-200 5, Parrot Foundation.1 #!parrot 2 # Copyright (C) 2001-2009, Parrot Foundation. 3 3 # $Id$ 4 4 5 use strict;6 use warnings;7 use lib qw( . lib ../lib ../../lib );8 use Test::More;9 use Parrot::Test tests => 6;10 11 5 =head1 NAME 12 6 13 7 t/op/ifunless.t - If/Unless … … 22 16 23 17 =cut 24 18 25 pasm_output_is( <<CODE, <<OUTPUT, "if_i_ic" ); 26 set I0, 2147483647 27 set I1, -2147483648 28 set I2, 0 19 .const int TESTS = 14 29 20 30 if I0, ONE 31 branch ERROR 32 print "bad\\n" 21 .sub 'test' :main 22 .include 'test_more.pir' 33 23 34 ONE: 35 print "ok 1\\n" 36 if I1, TWO 37 branch ERROR 38 print "bad\\n" 24 plan(TESTS) 39 25 40 TWO: 41 print "ok 2\\n" 42 if I2, ERROR 43 branch THREE 44 print "bad\\n" 26 if_i_ic_positive() 27 if_i_ic_negative() 28 if_i_ic_zero() 29 if_n_ic_positive() 30 if_n_ic_negative() 31 if_n_ic_zero() 32 if_s_ic_helloworld() 33 if_s_ic_empty() 45 34 46 THREE: 47 print "ok 3\\n" 48 end 35 unless_i_ic_zero() 36 unless_i_ic_negative() 37 unless_n_ic_zero() 38 unless_n_ic_negative() 39 unless_s_ic_empty() 40 unless_s_ic_helloworld() 49 41 50 ERROR: 51 print "bad\\n" 52 end 53 CODE 54 ok 1 55 ok 2 56 ok 3 57 OUTPUT 42 .end 58 43 59 pasm_output_is( <<CODE, <<OUTPUT, "if_n_ic" ); 60 set N0, 0.1 61 set N1, -0.1 62 set N2, 0.0 44 .sub 'if_i_ic_positive' 45 $I0 = 2147483647 63 46 64 if N0, ONE65 branch ERROR66 print "bad\\n"47 $I1 = 0 48 if $I0 goto if_i_ic_positive_ok 49 goto if_i_ic_positive_end 67 50 68 ONE:69 print "ok 1\\n"70 if N1, TWO71 branch ERROR72 print "bad\\n" 51 if_i_ic_positive_ok: 52 $I1 = 1 53 if_i_ic_positive_end: 54 ok($I1, "if_i_ic with a positive integer") 55 .end 73 56 74 TWO: 75 print "ok 2\\n" 76 if N2, ERROR 77 branch THREE 78 print "bad\\n" 57 .sub 'if_i_ic_negative' 58 $I0 = -2147483647 79 59 80 THREE: 81 print "ok 3\\n"82 60 $I1 = 0 61 if $I0 goto if_i_ic_negative_ok 62 goto if_i_ic_negative_end 83 63 84 ERROR: 85 print "bad\\n" 86 end 87 CODE 88 ok 1 89 ok 2 90 ok 3 91 OUTPUT 64 if_i_ic_negative_ok: 65 $I1 = 1 66 if_i_ic_negative_end: 67 ok($I1, "if_i_ic with a negative integer") 68 .end 92 69 93 pasm_output_is( <<CODE, <<OUTPUT, "if_s_ic" ); 94 set S0, "Hello World" 95 set S1, "" 70 .sub 'if_i_ic_zero' 71 $I0 = 0 96 72 97 if S0, ONE98 branch ERROR99 print "bad\\n"73 $I1 = 0 74 if $I0 goto if_i_ic_zero_end 75 $I1 = 1 100 76 101 ONE: 102 print "ok 1\\n" 103 if S1, ERROR 104 branch TWO 105 print "bad\\n" 77 if_i_ic_zero_end: 78 ok($I1, "if_i_ic with integer zero") 79 .end 106 80 107 TWO: 108 print "ok 2\\n" 109 end 81 .sub 'if_n_ic_positive' 82 $N0 = 0.1 110 83 111 ERROR: 112 print "bad\\n" 113 end 114 CODE 115 ok 1 116 ok 2 117 OUTPUT 84 $I1 = 0 85 if $N0 goto if_n_ic_positive_ok 86 goto if_n_ic_positive_end 118 87 119 pasm_output_is( <<CODE, <<OUTPUT, "unless_i_ic" ); 120 set I0, 0 121 set I1, -2147483648 88 if_n_ic_positive_ok: 89 $I1 = 1 90 if_n_ic_positive_end: 91 ok($I1, "if_n_ic with a positive float") 92 .end 122 93 123 unless I0, ONE 124 branch ERROR 125 print "bad\\n" 94 .sub 'if_n_ic_negative' 95 $N0 = -0.1 126 96 127 ONE: 128 print "ok 1\\n" 129 unless I1, ERROR 130 branch TWO 131 print "bad\\n" 97 $I1 = 0 98 if $N0 goto if_n_ic_negative_ok 99 goto if_n_ic_negative_end 132 100 133 TWO: 134 print "ok 2\\n" 135 end 101 if_n_ic_negative_ok: 102 $I1 = 1 103 if_n_ic_negative_end: 104 ok($I1, "if_n_ic with a negative float") 105 .end 136 106 137 ERROR: 138 print "bad\\n" 139 end 140 CODE 141 ok 1 142 ok 2 143 OUTPUT 107 .sub 'if_n_ic_zero' 108 $N0 = 0.0 144 109 145 pasm_output_is( <<CODE, <<OUTPUT, "unless_n_ic" ); 146 set N0, 0.0147 set N1, -0.1110 $I1 = 0 111 if $N0 goto if_n_ic_zero_end 112 $I1 = 1 148 113 149 unless N0, ONE150 branch ERROR151 print "bad\\n" 114 if_n_ic_zero_end: 115 ok($I1, "if_n_ic with float zero") 116 .end 152 117 153 ONE: 154 print "ok 1\\n" 155 unless N1, ERROR 156 branch TWO 157 print "bad\\n" 118 .sub 'if_s_ic_helloworld' 119 $S0 = "Hello World" 158 120 159 TWO: 160 print "ok 2\\n"161 121 $I1 = 0 122 if $S0 goto if_s_ic_helloworld_ok 123 goto if_s_ic_helloworld_end 162 124 163 ERROR: 164 print "bad\\n" 165 end 166 CODE 167 ok 1 168 ok 2 169 OUTPUT 125 if_s_ic_helloworld_ok: 126 $I1 = 1 127 if_s_ic_helloworld_end: 128 ok($I1, "if_s_ic with a non-empty string") 129 .end 170 130 171 pasm_output_is( <<CODE, <<OUTPUT, "unless_s_ic" ); 172 set S1, "Hello World" 173 set S0, "" 131 .sub 'if_s_ic_empty' 132 $S0 = '' 174 133 175 unless S0, ONE176 branch ERROR177 print "bad\\n"134 $I1 = 0 135 if $S0 goto if_s_ic_empty_end 136 $I1 = 1 178 137 179 ONE: 180 print "ok 1\\n" 181 unless S1, ERROR 182 branch TWO 183 print "bad\\n" 138 if_s_ic_empty_end: 139 ok($I1, "if_n_ic with the empty string") 140 .end 184 141 185 TWO: 186 print "ok 2\\n" 187 end 142 .sub 'unless_i_ic_zero' 143 $I0 = 0 188 144 189 ERROR: 190 print "bad\\n" 191 end 192 CODE 193 ok 1 194 ok 2 195 OUTPUT 145 $I1 = 0 146 unless $I0 goto unless_i_ic_zero_ok 147 goto unless_i_ic_zero_end 196 148 149 unless_i_ic_zero_ok: 150 $I1 = 1 151 unless_i_ic_zero_end: 152 ok($I1, "unless_i_ic with integer zero") 153 .end 154 155 .sub 'unless_i_ic_negative' 156 $I0 = -2147483648 157 158 $I1 = 0 159 unless $I0 goto unless_i_ic_negative_end 160 $I1 = 1 161 162 unless_i_ic_negative_end: 163 ok($I1, "unless_i_ic with a negative integer") 164 .end 165 166 .sub 'unless_n_ic_zero' 167 $N0 = 0.0 168 169 $I1 = 0 170 unless $N0 goto unless_n_ic_zero_ok 171 goto unless_n_ic_zero_end 172 173 unless_n_ic_zero_ok: 174 $I1 = 1 175 unless_n_ic_zero_end: 176 ok($I1, "unless_n_ic with float zero") 177 .end 178 179 .sub 'unless_n_ic_negative' 180 $N0 = -0.1 181 182 $I1 = 0 183 unless $N0 goto unless_n_ic_negative_end 184 $I1 = 1 185 186 unless_n_ic_negative_end: 187 ok($I1, "unless_n_ic with a negative float") 188 .end 189 190 .sub 'unless_s_ic_empty' 191 $S0 = '' 192 193 $I1 = 0 194 unless $S0 goto unless_s_ic_empty_ok 195 goto unless_s_ic_empty_end 196 197 unless_s_ic_empty_ok: 198 $I1 = 1 199 unless_s_ic_empty_end: 200 ok($I1, "unless_s_ic with the empty string") 201 .end 202 203 .sub 'unless_s_ic_helloworld' 204 $S0 = "Hello World" 205 206 $I1 = 0 207 unless $S0 goto unless_s_ic_helloworld_end 208 $I1 = 1 209 210 unless_s_ic_helloworld_end: 211 ok($I1, "unless_s_ic with a non-empty string") 212 .end 213 197 214 # Local Variables: 198 # mode: cperl 199 # cperl-indent-level: 4 215 # mode: pir 200 216 # fill-column: 100 201 217 # End: 202 # vim: expandtab shiftwidth=4 :218 # vim: expandtab shiftwidth=4 ft=pir: