Quick integration of mainline changes to date
[p5sagit/p5-mst-13.2.git] / t / op / lex_assign.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     unshift @INC, '../lib';
6 }
7 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3; 
8
9 umask 0;
10 $xref = \ "";
11 $runme = ($^O eq 'VMS' ? 'MCR ' : '') . $^X;
12 @a = (1..5);
13 %h = (1..6);
14 $aref = \@a;
15 $href = \%h;
16 open OP, qq{$runme -le "print 'aaa Ok ok' for 1..100"|};
17 $chopit = 'aaaaaa';
18 @chopar = (113 .. 119);
19 $posstr = '123456';
20 $cstr = 'aBcD.eF';
21 pos $posstr = 3;
22 $nn = $n = 2;
23 sub subb {"in s"}
24
25 @INPUT = <DATA>;
26 @simple_input = grep /^\s*\w+\s*\$\w+\s*[#\n]/, @INPUT;
27 print "1..", (9 + @INPUT + @simple_input), "\n";
28 $ord = 0;
29
30 sub wrn {"@_"}
31
32 # Check correct optimization of ucfirst etc
33 $ord++;
34 my $a = "AB";
35 my $b = "\u\L$a";
36 print "not " unless $b eq 'Ab';
37 print "ok $ord\n";
38
39 # Check correct destruction of objects:
40 my $dc = 0;
41 sub A::DESTROY {$dc += 1}
42 $a=8;
43 my $b;
44 { my $c = 6; $b = bless \$c, "A"}
45
46 $ord++;
47 print "not " unless $dc == 0;
48 print "ok $ord\n";
49
50 $b = $a+5;
51
52 $ord++;
53 print "not " unless $dc == 1;
54 print "ok $ord\n";
55
56 $ord++;
57 my $xxx = 'b';
58 $xxx = 'c' . ($xxx || 'e');
59 print "not " unless $xxx eq 'cb';
60 print "ok $ord\n";
61
62 {                               # Check calling STORE
63   my $sc = 0;
64   sub B::TIESCALAR {bless [11], 'B'}
65   sub B::FETCH { -(shift->[0]) }
66   sub B::STORE { $sc++; my $o = shift; $o->[0] = 17 + shift }
67
68   my $m;
69   tie $m, 'B';
70   $m = 100;
71
72   $ord++;
73   print "not " unless $sc == 1;
74   print "ok $ord\n";
75
76   my $t = 11;
77   $m = $t + 89;
78   
79   $ord++;
80   print "not " unless $sc == 2;
81   print "ok $ord\n";
82
83   $ord++;
84   print "# $m\nnot " unless $m == -117;
85   print "ok $ord\n";
86
87   $m += $t;
88
89   $ord++;
90   print "not " unless $sc == 3;
91   print "ok $ord\n";
92
93   $ord++;
94   print "# $m\nnot " unless $m == 89;
95   print "ok $ord\n";
96
97 }
98
99 for (@INPUT) {
100   $ord++;
101   ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
102   $comment = $op unless defined $comment;
103   $op = "$op==$op" unless $op =~ /==/;
104   ($op, $expectop) = $op =~ /(.*)==(.*)/;
105   
106   $skip = ($op =~ /^'\?\?\?'/ or $comment =~ /skip\(.*\Q$^O\E.*\)/i)
107           ? "skip" : "not";
108   $integer = ($comment =~ /^i_/) ? "use integer" : '' ;
109   (print "#skipping $comment:\nok $ord\n"), next if $skip eq 'skip';
110   
111   eval <<EOE;
112   local \$SIG{__WARN__} = \\&wrn;
113   my \$a = 'fake';
114   $integer;
115   \$a = $op;
116   \$b = $expectop;
117   if (\$a ne \$b) {
118     print "# \$comment: got `\$a', expected `\$b'\n";
119     print "\$skip " if \$a ne \$b or \$skip eq 'skip';
120   }
121   print "ok \$ord\\n";
122 EOE
123   if ($@) {
124     if ($@ =~ /is unimplemented/) {
125       print "# skipping $comment: unimplemented:\nok $ord\n";
126     } else {
127       warn $@;
128       print "not ok $ord\n";
129     }
130   }
131 }
132
133 for (@simple_input) {
134   $ord++;
135   ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
136   $comment = $op unless defined $comment;
137   ($operator, $variable) = /^\s*(\w+)\s*\$(\w+)/ or warn "misprocessed '$_'\n";
138   eval <<EOE;
139   local \$SIG{__WARN__} = \\&wrn;
140   my \$$variable = "Ac# Ca\\nxxx";
141   \$$variable = $operator \$$variable;
142   \$toself = \$$variable;
143   \$direct = $operator "Ac# Ca\\nxxx";
144   print "# \\\$$variable = $operator \\\$$variable\\nnot "
145     unless \$toself eq \$direct;
146   print "ok \$ord\\n";
147 EOE
148   if ($@) {
149     if ($@ =~ /is unimplemented/) {
150       print "# skipping $comment: unimplemented:\nok $ord\n";
151     } elsif ($@ =~ /Can't (modify|take log of 0)/) {
152       print "# skipping $comment: syntax not good for selfassign:\nok $ord\n";
153     } else {
154       warn $@;
155       print "not ok $ord\n";
156     }
157   }
158 }
159 __END__
160 ref $xref                       # ref
161 ref $cstr                       # ref nonref
162 `$runme -e "print qq[1\n]"`                             # backtick skip(MSWin32)
163 `$undefed`                      # backtick undef skip(MSWin32)
164 <*>                             # glob
165 <OP>                            # readline
166 'faked'                         # rcatline
167 (@z = (1 .. 3))                 # aassign
168 chop $chopit                    # chop
169 (chop (@x=@chopar))             # schop
170 chomp $chopit                   # chomp
171 (chop (@x=@chopar))             # schomp
172 pos $posstr                     # pos
173 pos $chopit                     # pos returns undef
174 $nn++==2                        # postinc
175 $nn++==3                        # i_postinc
176 $nn--==4                        # postdec
177 $nn--==3                        # i_postdec
178 $n ** $n                        # pow
179 $n * $n                         # multiply
180 $n * $n                         # i_multiply
181 $n / $n                         # divide
182 $n / $n                         # i_divide
183 $n % $n                         # modulo
184 $n % $n                         # i_modulo
185 $n x $n                         # repeat
186 $n + $n                         # add
187 $n + $n                         # i_add
188 $n - $n                         # subtract
189 $n - $n                         # i_subtract
190 $n . $n                         # concat
191 $n . $a=='2fake'                # concat with self
192 "3$a"=='3fake'                  # concat with self in stringify
193 "$n"                            # stringify
194 $n << $n                        # left_shift
195 $n >> $n                        # right_shift
196 $n <=> $n                       # ncmp
197 $n <=> $n                       # i_ncmp
198 $n cmp $n                       # scmp
199 $n & $n                         # bit_and
200 $n ^ $n                         # bit_xor
201 $n | $n                         # bit_or
202 -$n                             # negate
203 -$n                             # i_negate
204 ~$n                             # complement
205 atan2 $n,$n                     # atan2
206 sin $n                          # sin
207 cos $n                          # cos
208 '???'                           # rand
209 exp $n                          # exp
210 log $n                          # log
211 sqrt $n                         # sqrt
212 int $n                          # int
213 hex $n                          # hex
214 oct $n                          # oct
215 abs $n                          # abs
216 length $posstr                  # length
217 substr $posstr, 2, 2            # substr
218 vec("abc",2,8)                  # vec
219 index $posstr, 2                # index
220 rindex $posstr, 2               # rindex
221 sprintf "%i%i", $n, $n          # sprintf
222 ord $n                          # ord
223 chr $n                          # chr
224 crypt $n, $n                    # crypt
225 ucfirst ($cstr . "a")           # ucfirst padtmp
226 ucfirst $cstr                   # ucfirst
227 lcfirst $cstr                   # lcfirst
228 uc $cstr                        # uc
229 lc $cstr                        # lc
230 quotemeta $cstr                 # quotemeta
231 @$aref                          # rv2av
232 @$undefed                       # rv2av undef
233 each %h==1                      # each
234 values %h                       # values
235 keys %h                         # keys
236 %$href                          # rv2hv
237 pack "C2", $n,$n                # pack
238 split /a/, "abad"               # split
239 join "a"; @a                    # join
240 push @a,3==6                    # push
241 unshift @aaa                    # unshift
242 reverse @a                      # reverse
243 reverse $cstr                   # reverse - scal
244 grep $_, 1,0,2,0,3              # grepwhile
245 map "x$_", 1,0,2,0,3            # mapwhile
246 subb()                          # entersub
247 caller                          # caller
248 warn "ignore this\n"            # warn
249 'faked'                         # die
250 open BLAH, "<non-existent"      # open
251 fileno STDERR                   # fileno
252 umask 0                         # umask
253 select STDOUT                   # sselect
254 select "","","",0               # select
255 getc OP                         # getc
256 '???'                           # read
257 '???'                           # sysread
258 '???'                           # syswrite
259 '???'                           # send
260 '???'                           # recv
261 '???'                           # tell
262 '???'                           # fcntl
263 '???'                           # ioctl
264 '???'                           # flock
265 '???'                           # accept
266 '???'                           # shutdown
267 '???'                           # ftsize
268 '???'                           # ftmtime
269 '???'                           # ftatime
270 '???'                           # ftctime
271 chdir 'non-existent'            # chdir
272 '???'                           # chown
273 '???'                           # chroot
274 unlink 'non-existent'           # unlink
275 chmod 'non-existent'            # chmod
276 utime 'non-existent'            # utime
277 rename 'non-existent', 'non-existent1'  # rename
278 link 'non-existent', 'non-existent1' # link
279 '???'                           # symlink
280 readlink 'non-existent', 'non-existent1' # readlink
281 '???'                           # mkdir
282 '???'                           # rmdir
283 '???'                           # telldir
284 '???'                           # fork
285 '???'                           # wait
286 '???'                           # waitpid
287 system "$runme -e 0"            # system skip(VMS)
288 '???'                           # exec
289 '???'                           # kill
290 getppid                         # getppid
291 getpgrp                         # getpgrp
292 '???'                           # setpgrp
293 getpriority $$, $$              # getpriority
294 '???'                           # setpriority
295 time                            # time
296 localtime $^T                   # localtime
297 gmtime $^T                      # gmtime
298 sleep 1                         # sleep
299 '???'                           # alarm
300 '???'                           # shmget
301 '???'                           # shmctl
302 '???'                           # shmread
303 '???'                           # shmwrite
304 '???'                           # msgget
305 '???'                           # msgctl
306 '???'                           # msgsnd
307 '???'                           # msgrcv
308 '???'                           # semget
309 '???'                           # semctl
310 '???'                           # semop
311 '???'                           # getlogin
312 '???'                           # syscall