This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[ID 20010822.007] eval STRING & diagnostics.pm not mixing
[perl5.git] / t / op / ver.t
CommitLineData
3cb0bbe5
GS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
3cb0bbe5
GS
6}
7
62ec34bd 8print "1..37\n";
3cb0bbe5
GS
9
10my $test = 1;
11
fd36d4b8
JH
12sub okeq {
13 my $ok = $_[0] eq $_[1];;
14 print "not " unless $ok;
15 print "ok ", $test++;
16 print " # $_[2]" if !$ok && @_ == 3;
17 print "\n";
18}
19
20sub skip { print "ok ", $test++, " # Skip: $_[0]\n" }
21
3cb0bbe5
GS
22use v5.5.640;
23require v5.5.640;
24print "ok $test\n"; ++$test;
25
e526c9e6 26# printing characters should work
7bd40e26
PP
27if (ord("\t") == 9) { # ASCII
28 print v111;
29 print v107.32;
30 print "$test\n"; ++$test;
31
32 # hash keys too
33 $h{v111.107} = "ok";
34 print "$h{ok} $test\n"; ++$test;
35}
36else { # EBCDIC
37 print v150;
38 print v146.64;
39 print "$test\n"; ++$test;
40
41 # hash keys too
42 $h{v150.146} = "ok";
43 print "$h{ok} $test\n"; ++$test;
44}
e526c9e6
GS
45
46# poetry optimization should also
47sub v77 { "ok" }
48$x = v77;
49print "$x $test\n"; ++$test;
50
51# but not when dots are involved
7bd40e26
PP
52if (ord("\t") == 9) { # ASCII
53 $x = v77.78.79;
54}
55else {
56 $x = v212.213.214;
57}
fd36d4b8 58okeq($x, "MNO");
e526c9e6 59
fd36d4b8 60okeq(v1.20.300.4000, "\x{1}\x{14}\x{12c}\x{fa0}");
3cb0bbe5 61
dd629d5b
GS
62#
63# now do the same without the "v"
64use 5.5.640;
65require 5.5.640;
66print "ok $test\n"; ++$test;
67
68# hash keys too
7bd40e26
PP
69if (ord("\t") == 9) { # ASCII
70 $h{111.107.32} = "ok";
71}
72else {
73 $h{150.146.64} = "ok";
74}
dd629d5b
GS
75print "$h{ok } $test\n"; ++$test;
76
7bd40e26
PP
77if (ord("\t") == 9) { # ASCII
78 $x = 77.78.79;
79}
80else {
81 $x = 212.213.214;
82}
fd36d4b8 83okeq($x, "MNO");
dd629d5b 84
fd36d4b8 85okeq(1.20.300.4000, "\x{1}\x{14}\x{12c}\x{fa0}");
dd629d5b
GS
86
87# test sprintf("%vd"...) etc
7bd40e26 88if (ord("\t") == 9) { # ASCII
fd36d4b8 89 okeq(sprintf("%vd", "Perl"), '80.101.114.108');
7bd40e26
PP
90}
91else {
fd36d4b8 92 okeq(sprintf("%vd", "Perl"), '215.133.153.147');
7bd40e26 93}
3cb0bbe5 94
fd36d4b8 95okeq(sprintf("%vd", v1.22.333.4444), '1.22.333.4444');
b22c7a20 96
7bd40e26 97if (ord("\t") == 9) { # ASCII
fd36d4b8 98 okeq(sprintf("%vx", "Perl"), '50.65.72.6c');
7bd40e26
PP
99}
100else {
fd36d4b8 101 okeq(sprintf("%vx", "Perl"), 'd7.85.99.93');
7bd40e26 102}
b22c7a20 103
fd36d4b8 104okeq(sprintf("%vX", 1.22.333.4444), '1.16.14D.115C');
b22c7a20 105
7bd40e26 106if (ord("\t") == 9) { # ASCII
fd36d4b8 107 okeq(sprintf("%#*vo", ":", "Perl"), '0120:0145:0162:0154');
7bd40e26
PP
108}
109else {
fd36d4b8 110 okeq(sprintf("%#*vo", ":", "Perl"), '0327:0205:0231:0223');
7bd40e26 111}
b22c7a20 112
fd36d4b8
JH
113okeq(sprintf("%*vb", "##", v1.22.333.4444),
114 '1##10110##101001101##1000101011100');
3cb0bbe5 115
fd36d4b8
JH
116okeq(sprintf("%vd", join("", map { chr }
117 unpack 'U*', pack('U*',2001,2002,2003))),
118 '2001.2002.2003');
8dbfaa5d 119
3cb0bbe5 120{
8058d7ab 121 use bytes;
fd36d4b8 122
7bd40e26 123 if (ord("\t") == 9) { # ASCII
fd36d4b8 124 okeq(sprintf("%vd", "Perl"), '80.101.114.108');
7bd40e26
PP
125 }
126 else {
fd36d4b8 127 okeq(sprintf("%vd", "Perl"), '215.133.153.147');
7bd40e26 128 }
b22c7a20 129
210db7fc 130 if (ord("\t") == 9) { # ASCII
fd36d4b8 131 okeq(sprintf("%vd", 1.22.333.4444), '1.22.197.141.225.133.156');
210db7fc
PP
132 }
133 else {
fd36d4b8 134 okeq(sprintf("%vd", 1.22.333.4444), '1.22.142.84.187.81.112');
210db7fc 135 }
b22c7a20 136
7bd40e26 137 if (ord("\t") == 9) { # ASCII
fd36d4b8 138 okeq(sprintf("%vx", "Perl"), '50.65.72.6c');
7bd40e26
PP
139 }
140 else {
fd36d4b8 141 okeq(sprintf("%vx", "Perl"), 'd7.85.99.93');
7bd40e26 142 }
b22c7a20 143
210db7fc 144 if (ord("\t") == 9) { # ASCII
fd36d4b8 145 okeq(sprintf("%vX", v1.22.333.4444), '1.16.C5.8D.E1.85.9C');
210db7fc
PP
146 }
147 else {
fd36d4b8 148 okeq(sprintf("%vX", v1.22.333.4444), '1.16.8E.54.BB.51.70');
210db7fc 149 }
b22c7a20 150
7bd40e26 151 if (ord("\t") == 9) { # ASCII
fd36d4b8 152 okeq(sprintf("%#*vo", ":", "Perl"), '0120:0145:0162:0154');
7bd40e26
PP
153 }
154 else {
fd36d4b8 155 okeq(sprintf("%#*vo", ":", "Perl"), '0327:0205:0231:0223');
7bd40e26 156 }
b22c7a20 157
210db7fc 158 if (ord("\t") == 9) { # ASCII
fd36d4b8
JH
159 okeq(sprintf("%*vb", "##", v1.22.333.4444),
160 '1##10110##11000101##10001101##11100001##10000101##10011100');
210db7fc
PP
161 }
162 else {
fd36d4b8
JH
163 okeq(sprintf("%*vb", "##", v1.22.333.4444),
164 '1##10110##10001110##1010100##10111011##1010001##1110000');
210db7fc 165 }
3cb0bbe5 166}
00387047
JH
167
168{
fd36d4b8
JH
169 # 24..28
170
00387047
JH
171 # bug id 20000323.056
172
173 print "not " unless "\x{41}" eq +v65;
174 print "ok $test\n";
175 $test++;
176
177 print "not " unless "\x41" eq +v65;
178 print "ok $test\n";
179 $test++;
180
181 print "not " unless "\x{c8}" eq +v200;
182 print "ok $test\n";
183 $test++;
184
185 print "not " unless "\xc8" eq +v200;
186 print "ok $test\n";
187 $test++;
188
189 print "not " unless "\x{221b}" eq v8731;
190 print "ok $test\n";
191 $test++;
192}
fd36d4b8
JH
193
194# See if the things Camel-III says are true: 29..33
195
196# Chapter 2 pp67/68
197my $vs = v1.20.300.4000;
198okeq($vs,"\x{1}\x{14}\x{12c}\x{fa0}","v-string ne \\x{}");
199okeq($vs,chr(1).chr(20).chr(300).chr(4000),"v-string ne chr()");
200okeq('foo',((chr(193) eq 'A') ? v134.150.150 : v102.111.111),"v-string ne ''");
201
202# Chapter 15, pp403
203
204# See if sane addr and gethostbyaddr() work
2a52c5cc 205eval { require Socket; gethostbyaddr(v127.0.0.1, Socket::AF_INET) };
fd36d4b8
JH
206if ($@)
207 {
208 # No - so don't test insane fails.
e14f2162 209 $@ =~ s/\n/\n# /g;
2a52c5cc 210 skip("No Socket::AF_INET # $@");
fd36d4b8
JH
211 }
212else
213 {
214 my $ip = v2004.148.0.1;
215 my $host;
2a52c5cc 216 eval { $host = gethostbyaddr($ip,Socket::AF_INET) };
fd36d4b8
JH
217 okeq($@ =~ /Wide character/,1,"Non-bytes leak to gethostbyaddr");
218 }
219
220# Chapter 28, pp671
221okeq(v5.6.0 lt v5.7.0,1,"v5.6.0 lt v5.7.0 fails");
222
223# floating point too messy
224# my $v = ord($^V)+ord(substr($^V,1,1))/1000+ord(substr($^V,2,1))/1000000;
225# okeq($v,$],"\$^V and \$] do not match");
62ec34bd
JH
226
227# 34..37: part of 20000323.059
228print "not " unless v200 eq chr(200);
229print "ok 34\n";
230
231print "not " unless v200 eq +v200;
232print "ok 35\n";
233
234print "not " unless v200 eq eval "v200";
235print "ok 36\n";
236
237print "not " unless v200 eq eval "+v200";
238print "ok 37\n";
239