This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add testsuite portion of patch
[perl5.git] / t / op / lex_assign.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7
8 umask 0;
9 $xref = \ "";
10 @a = (1..5);
11 %h = (1..6);
12 $aref = \@a;
13 $href = \%h;
14 open OP, qq{$^X -le 'print "aaa Ok ok" while \$i++ < 100'|};
15 $chopit = 'aaaaaa';
16 @chopar = (113 .. 119);
17 $posstr = '123456';
18 $cstr = 'aBcD.eF';
19 pos $posstr = 3;
20 $nn = $n = 2;
21 sub subb {"in s"}
22
23 @INPUT = <DATA>;
24 print "1..", (scalar @INPUT), "\n";
25 $ord = 0;
26
27 sub wrn {"@_"}
28
29 for (@INPUT) {
30   $ord++;
31   ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
32   $comment = $op unless defined $comment;
33   $op = "$op==$op" unless $op =~ /==/;
34   ($op, $expectop) = $op =~ /(.*)==(.*)/;
35   
36   $skip = ($op =~ /^'\?\?\?'/) ? "skip" : "not";
37   $integer = ($comment =~ /^i_/) ? "use integer" : '' ;
38   (print "#skipping $comment:\nok $ord\n"), next if $skip eq 'skip';
39   
40   eval <<EOE;
41   local \$SIG{__WARN__} = \\&wrn;
42   my \$a = 'fake';
43   $integer;
44   \$a = $op;
45   \$b = $expectop;
46   if (\$a ne \$b) {
47     print "# \$comment: got `\$a', expected `\$b'\n";
48     print "\$skip " if \$a ne \$b or \$skip eq 'skip';
49   }
50   print "ok \$ord\\n";
51 EOE
52   if ($@) {
53     if ($@ =~ /is unimplemented/) {
54       print "# skipping $comment: unimplemented:\nok $ord\n";
55     } else {
56       warn $@;
57       print "not ok $ord\n";
58     }
59   }
60 }
61 __END__
62 ref $xref                       # ref
63 ref $cstr                       # ref nonref
64 `ls`                            # backtick
65 `$undefed`                      # backtick undef
66 <*>                             # glob
67 <OP>                            # readline
68 'faked'                         # rcatline
69 (@z = (1 .. 3))                 # aassign
70 chop $chopit                    # chop
71 (chop (@x=@chopar))             # schop
72 chomp $chopit                   # chomp
73 (chop (@x=@chopar))             # schomp
74 pos $posstr                     # pos
75 pos $chopit                     # pos returns undef
76 $nn++==2                        # postinc
77 $nn++==3                        # i_postinc
78 $nn--==4                        # postdec
79 $nn--==3                        # i_postdec
80 $n ** $n                        # pow
81 $n * $n                         # multiply
82 $n * $n                         # i_multiply
83 $n / $n                         # divide
84 $n / $n                         # i_divide
85 $n % $n                         # modulo
86 $n % $n                         # i_modulo
87 $n x $n                         # repeat
88 $n + $n                         # add
89 $n + $n                         # i_add
90 $n - $n                         # subtract
91 $n - $n                         # i_subtract
92 $n . $n                         # concat
93 $n . $a=='2fake'                # concat with self
94 "3$a"=='3fake'                  # concat with self in stringify
95 "$n"                            # stringify
96 $n << $n                        # left_shift
97 $n >> $n                        # right_shift
98 $n <=> $n                       # ncmp
99 $n <=> $n                       # i_ncmp
100 $n cmp $n                       # scmp
101 $n & $n                         # bit_and
102 $n ^ $n                         # bit_xor
103 $n | $n                         # bit_or
104 -$n                             # negate
105 -$n                             # i_negate
106 ~$n                             # complement
107 atan2 $n,$n                     # atan2
108 sin $n                          # sin
109 cos $n                          # cos
110 '???'                           # rand
111 exp $n                          # exp
112 log $n                          # log
113 sqrt $n                         # sqrt
114 int $n                          # int
115 hex $n                          # hex
116 oct $n                          # oct
117 abs $n                          # abs
118 length $posstr                  # length
119 substr $posstr, 2, 2            # substr
120 vec("abc",2,8)                  # vec
121 index $posstr, 2                # index
122 rindex $posstr, 2               # rindex
123 sprintf "%i%i", $n, $n          # sprintf
124 ord $n                          # ord
125 chr $n                          # chr
126 crypt $n, $n                    # crypt
127 ucfirst ($cstr . "a")           # ucfirst padtmp
128 ucfirst $cstr                   # ucfirst
129 lcfirst $cstr                   # lcfirst
130 uc $cstr                        # uc
131 lc $cstr                        # lc
132 quotemeta $cstr                 # quotemeta
133 @$aref                          # rv2av
134 @$undefed                       # rv2av undef
135 each %h==1                      # each
136 values %h                       # values
137 keys %h                         # keys
138 %$href                          # rv2hv
139 pack "C2", $n,$n                # pack
140 split /a/, "abad"               # split
141 join "a"; @a                    # join
142 push @a,3==6                    # push
143 unshift @aaa                    # unshift
144 reverse @a                      # reverse
145 reverse $cstr                   # reverse - scal
146 grep $_, 1,0,2,0,3              # grepwhile
147 map "x$_", 1,0,2,0,3            # mapwhile
148 subb()                          # entersub
149 caller                          # caller
150 warn "ignore this\n"            # warn
151 'faked'                         # die
152 open BLAH, "<non-existent"      # open
153 fileno STDERR                   # fileno
154 umask 0                         # umask
155 select STDOUT                   # sselect
156 select "","","",0               # select
157 getc OP                         # getc
158 '???'                           # read
159 '???'                           # sysread
160 '???'                           # syswrite
161 '???'                           # send
162 '???'                           # recv
163 '???'                           # tell
164 '???'                           # fcntl
165 '???'                           # ioctl
166 '???'                           # flock
167 '???'                           # accept
168 '???'                           # shutdown
169 '???'                           # ftsize
170 '???'                           # ftmtime
171 '???'                           # ftatime
172 '???'                           # ftctime
173 chdir 'non-existent'            # chdir
174 '???'                           # chown
175 '???'                           # chroot
176 unlink 'non-existent'           # unlink
177 chmod 'non-existent'            # chmod
178 utime 'non-existent'            # utime
179 rename 'non-existent', 'non-existent1'  # rename
180 link 'non-existent', 'non-existent1' # link
181 symlink 'non-existent', 'non-existent1' # symlink
182 readlink 'non-existent', 'non-existent1' # readlink
183 '???'                           # mkdir
184 '???'                           # rmdir
185 '???'                           # telldir
186 '???'                           # fork
187 '???'                           # wait
188 '???'                           # waitpid
189 system 'sh -c true'             # system
190 '???'                           # exec
191 kill 0, $$                      # kill
192 getppid                         # getppid
193 getpgrp                         # getpgrp
194 '???'                           # setpgrp
195 getpriority $$, $$              # getpriority
196 '???'                           # setpriority
197 time                            # time
198 localtime                       # localtime
199 gmtime                          # gmtime
200 sleep 1                         # sleep
201 '???'                           # alarm
202 '???'                           # shmget
203 '???'                           # shmctl
204 '???'                           # shmread
205 '???'                           # shmwrite
206 '???'                           # msgget
207 '???'                           # msgctl
208 '???'                           # msgsnd
209 '???'                           # msgrcv
210 '???'                           # semget
211 '???'                           # semctl
212 '???'                           # semop
213 '???'                           # getlogin
214 '???'                           # syscall