6 $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN };
9 $DOWARN = 1; # enable run-time warnings now
12 $tests = $Config{'uvsize'} == 8 ? 47 : 44;
15 plan( tests => $tests );
17 eval { use v5.5.640; };
18 is( $@, '', "use v5.5.640; $@");
20 require_ok('v5.5.640');
22 # printing characters should work
23 if (ord("\t") == 9) { # ASCII
24 is('ok ',v111.107.32,'ASCII printing characters');
28 is('ok',$h{v111.107},'ASCII hash keys');
31 is('ok ',v150.146.64,'EBCDIC printing characters');
35 is('ok',$h{v111.107},'ASCII hash keys');
38 # poetry optimization should also
41 is('ok',$x,'poetry optimization');
43 # but not when dots are involved
44 if (ord("\t") == 9) { # ASCII
50 is($x, 'MNO','poetry optimization with dots');
52 is(v1.20.300.4000, "\x{1}\x{14}\x{12c}\x{fa0}",'compare embedded \x{} string');
55 # now do the same without the "v"
56 eval { use 5.5.640; };
57 is( $@, '', "use 5.5.640; $@");
59 require_ok('5.5.640');
62 if (ord("\t") == 9) { # ASCII
63 $h{111.107.32} = "ok";
66 $h{150.146.64} = "ok";
68 is('ok',$h{ok },'hash keys w/o v');
70 if (ord("\t") == 9) { # ASCII
76 is($x, 'MNO','poetry optimization with dots w/o v');
78 is(1.20.300.4000, "\x{1}\x{14}\x{12c}\x{fa0}",'compare embedded \x{} string w/o v');
80 # test sprintf("%vd"...) etc
81 if (ord("\t") == 9) { # ASCII
82 is(sprintf("%vd", "Perl"), '80.101.114.108', 'ASCII sprintf("%vd", "Perl")');
85 is(sprintf("%vd", "Perl"), '215.133.153.147', 'EBCDIC sprintf("%vd", "Perl")');
88 is(sprintf("%vd", v1.22.333.4444), '1.22.333.4444', 'sprintf("%vd", v1.22.333.4444)');
90 if (ord("\t") == 9) { # ASCII
91 is(sprintf("%vx", "Perl"), '50.65.72.6c', 'ASCII sprintf("%vx", "Perl")');
94 is(sprintf("%vx", "Perl"), 'd7.85.99.93', 'EBCDIC sprintf("%vx", "Perl")');
97 is(sprintf("%vX", 1.22.333.4444), '1.16.14D.115C','ASCII sprintf("%vX", 1.22.333.4444)');
99 if (ord("\t") == 9) { # ASCII
100 is(sprintf("%#*vo", ":", "Perl"), '0120:0145:0162:0154', 'ASCII sprintf("%vo", "Perl")');
103 is(sprintf("%#*vo", ":", "Perl"), '0327:0205:0231:0223', 'EBCDIC sprintf("%vo", "Perl")');
106 is(sprintf("%*vb", "##", v1.22.333.4444),
107 '1##10110##101001101##1000101011100', 'sprintf("%vb", 1.22.333.4444)');
109 is(sprintf("%vd", join("", map { chr }
110 unpack 'U*', pack('U*',2001,2002,2003))),
111 '2001.2002.2003','unpack/pack U*');
116 if (ord("\t") == 9) { # ASCII
117 is(sprintf("%vd", "Perl"), '80.101.114.108', 'ASCII sprintf("%vd", "Perl") w/use bytes');
120 is(sprintf("%vd", "Perl"), '215.133.153.147', 'EBCDIC sprintf("%vd", "Perl") w/use bytes');
123 if (ord("\t") == 9) { # ASCII
124 is(sprintf("%vd", 1.22.333.4444), '1.22.197.141.225.133.156', 'ASCII sprintf("%vd", v1.22.333.4444 w/use bytes');
127 is(sprintf("%vd", 1.22.333.4444), '1.22.142.84.187.81.112', 'EBCDIC sprintf("%vd", v1.22.333.4444 w/use bytes');
130 if (ord("\t") == 9) { # ASCII
131 is(sprintf("%vx", "Perl"), '50.65.72.6c', 'ASCII sprintf("%vx", "Perl")');
134 is(sprintf("%vx", "Perl"), 'd7.85.99.93', 'EBCDIC sprintf("%vx", "Perl")');
137 if (ord("\t") == 9) { # ASCII
138 is(sprintf("%vX", v1.22.333.4444), '1.16.C5.8D.E1.85.9C', 'ASCII sprintf("%vX", v1.22.333.4444)');
141 is(sprintf("%vX", v1.22.333.4444), '1.16.8E.54.BB.51.70', 'EBCDIC sprintf("%vX", v1.22.333.4444)');
144 if (ord("\t") == 9) { # ASCII
145 is(sprintf("%#*vo", ":", "Perl"), '0120:0145:0162:0154', 'ASCII sprintf("%#*vo", ":", "Perl")');
148 is(sprintf("%#*vo", ":", "Perl"), '0327:0205:0231:0223', 'EBCDIC sprintf("%#*vo", ":", "Perl")');
151 if (ord("\t") == 9) { # ASCII
152 is(sprintf("%*vb", "##", v1.22.333.4444),
153 '1##10110##11000101##10001101##11100001##10000101##10011100',
154 'ASCII sprintf("%*vb", "##", v1.22.333.4444)');
157 is(sprintf("%*vb", "##", v1.22.333.4444),
158 '1##10110##10001110##1010100##10111011##1010001##1110000',
159 'EBCDIC sprintf("%*vb", "##", v1.22.333.4444)');
164 # bug id 20000323.056
166 is( "\x{41}", +v65, 'bug id 20000323.056');
167 is( "\x41", +v65, 'bug id 20000323.056');
168 is( "\x{c8}", +v200, 'bug id 20000323.056');
169 is( "\xc8", +v200, 'bug id 20000323.056');
170 is( "\x{221b}", +v8731, 'bug id 20000323.056');
173 # See if the things Camel-III says are true: 29..33
176 my $vs = v1.20.300.4000;
177 is($vs,"\x{1}\x{14}\x{12c}\x{fa0}","v-string ne \\x{}");
178 is($vs,chr(1).chr(20).chr(300).chr(4000),"v-string ne chr()");
179 is('foo',((chr(193) eq 'A') ? v134.150.150 : v102.111.111),"v-string ne ''");
183 # See if sane addr and gethostbyaddr() work
184 eval { require Socket; gethostbyaddr(v127.0.0.1, Socket::AF_INET) };
186 # No - so do not test insane fails.
190 skip("No Socket::AF_INET # $@") if $@;
191 my $ip = v2004.148.0.1;
193 eval { $host = gethostbyaddr($ip,Socket::AF_INET) };
194 ok($@ =~ /Wide character/,"Non-bytes leak to gethostbyaddr");
198 ok(v5.6.0 lt v5.7.0, "v5.6.0 lt v5.7.0");
200 # part of 20000323.059
201 is(v200, chr(200), "v200 eq chr(200)" );
202 is(v200, +v200, "v200 eq +v200" );
203 is(v200, eval( "v200"), 'v200 eq "v200"' );
204 is(v200, eval("+v200"), 'v200 eq eval("+v200")' );
206 # Tests for string/numeric value of $] itself
207 my ($revision,$version,$subversion) = split '\.', sprintf("%vd",$^V);
209 my $v = sprintf("%d.%.3d%.3d",$revision,$version,$subversion);
211 ok( $v eq "$]", "\$^V eq \$] (string)");
213 $v = $revision + $version/1000 + $subversion/1000000;
215 ok( $v == $], "\$^V == \$] (numeric)" );
217 # [ID 20010902.001] check if v-strings handle full UV range or not
218 if ( $Config{'uvsize'} >= 4 ) {
219 is( sprintf("%vd", v2147483647.2147483648), '2147483647.2147483648', 'v-string > IV_MAX[32-bit]' );
220 is( sprintf("%vd", v3141592653), '3141592653', 'IV_MAX < v-string < UV_MAX[32-bit]');
221 is( sprintf("%vd", v4294967295), '4294967295', 'v-string == UV_MAX[32-bit] - 1');
224 if ( $Config{'uvsize'} >= 8 ) {
225 is( sprintf("%vd", v9223372036854775807.9223372036854775808), '9223372036854775807.9223372036854775808', 'v-string > IV_MAX[64-bit]' );
226 is( sprintf("%vd", v17446744073709551615), '17446744073709551615', 'IV_MAX < v-string < UV_MAX[64-bit]');
227 is( sprintf("%vd", v18446744073709551615), '18446744073709551615', 'v-string == UV_MAX[64-bit] - 1');