Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 276 lines (220 sloc) 6.609 kB
8433461 @moritz fudge autoincrement.t for rakudo
moritz authored
1
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
2 use Test;
3
4 # Tests for auto-increment and auto-decrement operators
5 # originally from Perl 5, by way of t/operators/auto.t
6
3164e55 @usev6 Add test for RT #99732
usev6 authored
7 plan 79;
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
8
9 #L<S03/Autoincrement precedence>
10
11 my $base = 10000;
12
13 my $x = 10000;
426a346 [t/spec] Give every autoincrement test a name
kyle authored
14 is(0 + ++$x - 1, $base, '0 + ++$x - 1');
15 is(0 + $x-- - 1, $base, '0 + $x-- - 1');
16 is(1 * $x, $base, '1 * $x');
17 is(0 + $x-- - 0, $base, '0 + $x-- - 0');
18 is(1 + $x, $base, '1 + $x');
19 is(1 + $x++, $base, '1 + $x++');
20 is(0 + $x, $base, '0 + $x');
21 is(0 + --$x + 1, $base, '0 + --$x + 1');
22 is(0 + ++$x + 0, $base, '0 + ++$x + 0');
23 is($x, $base, '$x');
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
24
25 my @x;
26 @x[0] = 10000;
426a346 [t/spec] Give every autoincrement test a name
kyle authored
27 is(0 + ++@x[0] - 1, $base, '0 + ++@x[0] - 1');
28 is(0 + @x[0]-- - 1, $base, '0 + @x[0]-- - 1');
29 is(1 * @x[0], $base, '1 * @x[0]');
30 is(0 + @x[0]-- - 0, $base, '0 + @x[0]-- - 0');
31 is(1 + @x[0], $base, '1 + @x[0]');
32 is(1 + @x[0]++, $base, '1 + @x[0]++');
33 is(0 + @x[0], $base, '0 + @x[0]');
34 is(0 + ++@x[0] - 1, $base, '0 + ++@x[0] - 1');
35 is(0 + --@x[0] + 0, $base, '0 + --@x[0] + 0');
36 is(@x[0], $base, '@x[0]');
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
37
38 my %z;
39 %z{0} = 10000;
426a346 [t/spec] Give every autoincrement test a name
kyle authored
40 is(0 + ++%z{0} - 1, $base, '0 + ++%z{0} - 1');
41 is(0 + %z{0}-- - 1, $base, '0 + %z{0}-- - 1');
42 is(1 * %z{0}, $base, '1 * %z{0}');
43 is(0 + %z{0}-- - 0, $base, '0 + %z{0}-- - 0');
44 is(1 + %z{0}, $base, '1 + %z{0}');
45 is(1 + %z{0}++, $base, '1 + %z{0}++');
46 is(0 + %z{0}, $base, '0 + %z{0}');
47 is(0 + ++%z{0} - 1, $base, '0 + ++%z{0} - 1');
48 is(0 + --%z{0} + 0, $base, '0 + --%z{0} + 0');
49 is(%z{0}, $base, '%z{0}');
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
50
51 # Increment of a Str
52 #L<S03/Autoincrement precedence/Increment of a>
53
54 # XXX: these need to be re-examined and extended per changes to S03.
55 # Also, see the thread at
56 # http://www.nntp.perl.org/group/perl.perl6.compiler/2007/06/msg1598.html
57 # which prompted many of the changes to Str autoincrement/autodecrement.
58
7b951f4 [t/spec] Some notes about character ranges
kyle authored
59 {
60 # These are the ranges specified in S03.
61 # They might be handy for some DDT later.
62
63 my @rangechar = (
64 [ 'A', 'Z' ],
65 [ 'a', 'z' ],
66 [ "\x[391]", "\x[3a9]" ],
67 [ "\x[3b1]", "\x[3c9]" ],
68 [ "\x[5d0]", "\x[5ea]" ],
69
70 [ '0', '9' ],
71 [ "\x[660]", "\x[669]" ],
72 [ "\x[966]", "\x[96f]" ],
73 [ "\x[9e6]", "\x[9ef]" ],
74 [ "\x[a66]", "\x[a6f]" ],
75 [ "\x[ae6]", "\x[aef]" ],
76 [ "\x[b66]", "\x[b6f]" ],
77 );
78 }
79
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
80 {
81 my $x;
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
82
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
83 $x = "123.456";
84 is( ++$x, "124.456", "'123.456'++ is '124.456' (NOT 123.457)" );
85 $x = "124.456";
86 is( --$x, "123.456", "'124.456'-- is '123.456'" );
87 }
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
88
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
89 {
90 my $x;
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
91
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
92 $x = "/tmp/pix000.jpg";
93 is( ++$x, "/tmp/pix001.jpg", "'/tmp/pix000.jpg'++ is '/tmp/pix001.jpg'" );
94 $x = "/tmp/pix001.jpg";
95 is( --$x, "/tmp/pix000.jpg", "'/tmp/pix001.jpg'-- is '/tmp/pix000.jpg'" );
96 }
0d397ce [t/spec] Fix the decrement fail tests in autoincrement.t
kyle authored
97
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
98 {
99 my $x;
f67acb2 * Add two more tests for string autoincrement.
pmichaud authored
100
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
101 # EBCDIC check (i and j not contiguous)
102 $x = "zi";
103 is( ++$x, "zj", "'zi'++ is 'zj'" );
104 $x = "zj";
105 is( --$x, "zi", "'zj'-- is 'zi'" );
106 $x = "zr";
107
108 # EBCDIC check (r and s not contiguous)
109 is( ++$x, "zs", "'zr'++ is 'zs'" );
110 $x = "zs";
111 is( --$x, "zr", "'zs'-- is 'zr'" );
112 }
f1e2666 [t/spec] Add Greek tests to autoincrement
kyle authored
113
6c5c1dd @colomon Fudge for niecza.
colomon authored
114 #?niecza skip "Failure NYI"
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
115 {
116 my $foo;
f1e2666 [t/spec] Add Greek tests to autoincrement
kyle authored
117
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
118 $foo = 'A00';
119 ok(--$foo ~~ Failure, "Decrement of 'A00' should fail");
2c8c0a7 [t/spec] Added some more greek autoincrement tests
kyle authored
120
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
121 # TODO: Check that the Failure is "Decrement out of range" and not
122 # some other unrelated error (for the fail tests above).
123 }
2c8c0a7 [t/spec] Added some more greek autoincrement tests
kyle authored
124
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
125 {
126 my $foo;
2c8c0a7 [t/spec] Added some more greek autoincrement tests
kyle authored
127
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
128 $foo = "\x[3a1]";
129 is( ++$foo, "\x[3a3]", 'there is no \\x[3a2]' );
130 }
2c8c0a7 [t/spec] Added some more greek autoincrement tests
kyle authored
131
d438915 [t/spec] Bring autoincrement.t in line with autoincrement-range.t
kyle authored
132 {
133 my $foo = "K\x[3c9]";
134 is( ++$foo, "L\x[3b1]", "increment 'K\x[3c9]'" );
135 }
2c8c0a7 [t/spec] Added some more greek autoincrement tests
kyle authored
136
4270f97 [t] tests for autoincrementing uninitialized variables
moritz authored
137 {
138 my $x;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
139 is ++$x, 1, 'Can autoincrement a Mu variable (prefix)';
4270f97 [t] tests for autoincrementing uninitialized variables
moritz authored
140
141 my $y;
142 $y++;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
143 is $y, 1, 'Can autoincrement a Mu variable (postfix)';
4270f97 [t] tests for autoincrementing uninitialized variables
moritz authored
144 }
bb66a66 [t/spec/S03-operators/autoincrement.t] added tests for overriding suc…
masak authored
145
146 {
147 class Incrementor {
148 has $.value;
149
150 method succ() {
a56872b [spec] Made Incrementor/Decrementor behave according to S03.
bacek authored
151 Incrementor.new( value => $.value + 42);
bb66a66 [t/spec/S03-operators/autoincrement.t] added tests for overriding suc…
masak authored
152 }
153 }
154
155 my $o = Incrementor.new( value => 0 );
156 $o++;
157 is $o.value, 42, 'Overriding succ catches postfix increment';
158 ++$o;
159 is $o.value, 84, 'Overriding succ catches prefix increment';
160 }
161
162 {
163 class Decrementor {
164 has $.value;
165
166 method pred() {
a56872b [spec] Made Incrementor/Decrementor behave according to S03.
bacek authored
167 Decrementor.new( value => $.value - 42);
bb66a66 [t/spec/S03-operators/autoincrement.t] added tests for overriding suc…
masak authored
168 }
169 }
170
171 my $o = Decrementor.new( value => 100 );
172 $o--;
173 is $o.value, 58, 'Overriding pred catches postfix decrement';
174 --$o;
175 is $o.value, 16, 'Overriding pred catches prefix decrement';
176 }
8adc7f9 [tests] Added tests for .succ and .pred for Int, Str and Num and mark…
eric256 authored
177
178 {
179 # L<S03/Autoincrement precedence/Increment of a>
3164e55 @usev6 Add test for RT #99732
usev6 authored
180
7cbb4fa [t/spec]: Fudge autoincrement.t -- test may be incorrect
pmichaud authored
181 my $x = "b";
182 is $x.succ, 'c', '.succ for Str';
8adc7f9 [tests] Added tests for .succ and .pred for Int, Str and Num and mark…
eric256 authored
183 is $x.pred, 'a', '.pred for Str';
184
185 my $y = 1;
186 is $y.succ, 2, '.succ for Int';
187 is $y.pred, 0, '.pred for Int';
188
189 my $z = Num.new();
190 is $z.succ, 1 , '.succ for Num';
191 is $z.pred, -1, '.pred for Num'
192 }
404a5b4 [t/spec] Test for RT #63644
kyle authored
193
194 # RT #63644
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
195 eval-dies-ok 'my $a; $a++ ++;', 'parse error for "$a++ ++"';
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
196
3164e55 @usev6 Add test for RT #99732
usev6 authored
197 # RT #99731
198 {
199 $_ = 4;
200 .++;
201 is $_, 5, 'increment of $_ via .++';
202 }
203
f18a918 @pmichaud Add spectests for bool autoincrement (RT #113816).
pmichaud authored
204 # RT #113816 - autoincrement of bools
205 {
206 my Bool $x;
207 my $y;
208
209 #postincrement tests
210 $x = Bool;
211 $y = $x++;
212 is $y, False, "Bool postincrement returns Bool";
213 is $x, True, "Bool postincrement sets True";
214
215 $x = False;
216 $y = $x++;
217 is $y, False, "False postincrement returns False";
218 is $x, True, "False postincrement sets True";
219
220 $x = True;
221 $y = $x++;
222 is $y, True, "True postincrement returns True";
223 is $x, True, "True postincrement sets True";
224
225 #postdecrement tests
226 $x = Bool;
227 $y = $x--;
228 is $y, False, "Bool postdecrement returns Bool";
229 is $x, False, "Bool postdecrement sets False";
230
231 $x = False;
232 $y = $x--;
233 is $y, False, "False postdecrement returns False";
234 is $x, False, "False postdecrement sets False";
235
236 $x = True;
237 $y = $x--;
238 is $y, True, "True postdecrement returns True";
239 is $x, False, "True postdecrement sets False";
240
241 #preincrement tests
242 $x = Bool;
243 $y = ++$x;
244 is $y, True, "Bool preincrement returns True";
245 is $x, True, "Bool postincrement sets True";
246
247 $x = False;
248 $y = ++$x;
249 is $y, True, "False preincrement returns True";
250 is $x, True, "False postincrement sets True";
251
252 $x = True;
253 $y = ++$x;
254 is $y, True, "True preincrement returns True";
255 is $x, True, "True postincrement sets True";
3164e55 @usev6 Add test for RT #99732
usev6 authored
256
f18a918 @pmichaud Add spectests for bool autoincrement (RT #113816).
pmichaud authored
257 #predecrement tests
258 $x = Bool;
259 $y = --$x;
260 is $y, False, "Bool predecrement returns False";
261 is $x, False, "Bool postdecrement sets False";
262
263 $x = False;
264 $y = --$x;
265 is $y, False, "False predecrement returns False";
266 is $x, False, "False postdecrement sets False";
267
268 $x = True;
269 $y = --$x;
270 is $y, False, "True predecrement returns False";
271 is $x, False, "True postdecrement sets False";
272 };
273
274
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
275 # vim: ft=perl6
Something went wrong with that request. Please try again.