$DOWARN = 1; # enable run-time warnings now
use Config;
-$tests = $Config{'uvsize'} == 8 ? 47 : 44;
require "test.pl";
-plan( tests => $tests );
+plan( tests => 54 );
-eval { use v5.5.640; };
+eval 'use v5.5.640';
is( $@, '', "use v5.5.640; $@");
require_ok('v5.5.640');
#
# now do the same without the "v"
-eval { use 5.5.640; };
+eval 'use 5.5.640';
is( $@, '', "use 5.5.640; $@");
require_ok('5.5.640');
# Chapter 15, pp403
# See if sane addr and gethostbyaddr() work
-eval { require Socket; gethostbyaddr(v127.0.0.1, Socket::AF_INET) };
+eval { require Socket; gethostbyaddr(v127.0.0.1, &Socket::AF_INET) };
if ($@) {
# No - so do not test insane fails.
$@ =~ s/\n/\n# /g;
skip("No Socket::AF_INET # $@") if $@;
my $ip = v2004.148.0.1;
my $host;
- eval { $host = gethostbyaddr($ip,Socket::AF_INET) };
- ok($@ =~ /Wide character/,"Non-bytes leak to gethostbyaddr");
+ eval { $host = gethostbyaddr($ip,&Socket::AF_INET) };
+ like($@, qr/Wide character/, "Non-bytes leak to gethostbyaddr");
}
# Chapter 28, pp671
is(v200, eval("+v200"), 'v200 eq eval("+v200")' );
# Tests for string/numeric value of $] itself
-my ($revision,$version,$subversion) = split '\.', sprintf("%vd",$^V);
+my ($revision,$version,$subversion) = split /\./, sprintf("%vd",$^V);
+
+# $^V always displays the leading 'v' but we don't want that here
+$revision =~ s/^v//;
+
+print "# revision = '$revision'\n";
+print "# version = '$version'\n";
+print "# subversion = '$subversion'\n";
my $v = sprintf("%d.%.3d%.3d",$revision,$version,$subversion);
-ok( $v eq "$]", qq{"\$^V eq "\$]"});
+print "# v = '$v'\n";
+print "# ] = '$]'\n";
+
+is( $v, "$]", qq{\$^V eq "\$]"});
$v = $revision + $version/1000 + $subversion/1000000;
-ok( $v == $], "\$^V == \$] (numeric)" );
+ok( abs($v - $]) < 10**-8 , "\$^V == \$] (numeric)" );
-# [ID 20010902.001] check if v-strings handle full UV range or not
-if ( $Config{'uvsize'} >= 4 ) {
- is( sprintf("%vd", v2147483647.2147483648), '2147483647.2147483648', 'v-string > IV_MAX[32-bit]' );
- is( sprintf("%vd", v3141592653), '3141592653', 'IV_MAX < v-string < UV_MAX[32-bit]');
- is( sprintf("%vd", v4294967295), '4294967295', 'v-string == UV_MAX[32-bit] - 1');
+SKIP: {
+ skip("In EBCDIC the v-string components cannot exceed 2147483647", 6)
+ if ord "A" == 193;
+
+ # [ID 20010902.001] check if v-strings handle full UV range or not
+ if ( $Config{'uvsize'} >= 4 ) {
+ is( sprintf("%vd", eval 'v2147483647.2147483648'), '2147483647.2147483648', 'v-string > IV_MAX[32-bit]' );
+ is( sprintf("%vd", eval 'v3141592653'), '3141592653', 'IV_MAX < v-string < UV_MAX[32-bit]');
+ is( sprintf("%vd", eval 'v4294967295'), '4294967295', 'v-string == UV_MAX[32-bit] - 1');
+ }
+
+ SKIP: {
+ skip("No quads", 3) if $Config{uvsize} < 8;
+
+ if ( $Config{'uvsize'} >= 8 ) {
+ is( sprintf("%vd", eval 'v9223372036854775807.9223372036854775808'), '9223372036854775807.9223372036854775808', 'v-string > IV_MAX[64-bit]' );
+ is( sprintf("%vd", eval 'v17446744073709551615'), '17446744073709551615', 'IV_MAX < v-string < UV_MAX[64-bit]');
+ is( sprintf("%vd", eval 'v18446744073709551615'), '18446744073709551615', 'v-string == UV_MAX[64-bit] - 1');
+ }
+ }
}
-if ( $Config{'uvsize'} >= 8 ) {
- is( sprintf("%vd", v9223372036854775807.9223372036854775808), '9223372036854775807.9223372036854775808', 'v-string > IV_MAX[64-bit]' );
- is( sprintf("%vd", v17446744073709551615), '17446744073709551615', 'IV_MAX < v-string < UV_MAX[64-bit]');
- is( sprintf("%vd", v18446744073709551615), '18446744073709551615', 'v-string == UV_MAX[64-bit] - 1');
-}
+# Tests for magic v-strings
+
+$v = 1.2.3;
+is( ref(\$v), 'VSTRING', 'v-string objects' );
+
+$v = v1.2_3;
+is( ref(\$v), 'VSTRING', 'v-string objects with v' );
+is( sprintf("%vd", $v), '1.23', 'v-string ignores underscores' );
+
+# [perl #16010]
+%h = (v65 => 42);
+ok( exists $h{v65}, "v-stringness is not engaged for vX" );
+%h = (v65.66 => 42);
+ok( exists $h{chr(65).chr(66)}, "v-stringness is engaged for vX.Y" );
+%h = (65.66.67 => 42);
+ok( exists $h{chr(65).chr(66).chr(67)}, "v-stringness is engaged for X.Y.Z" );
+
+
+# The following tests whether v-strings are correctly
+# interpreted by the tokeniser when it's in a XTERMORDORDOR
+# state (fittingly, the only tokeniser state to contain the
+# word MORDOR).
+
+*{"\3"} = *DATA;
+is( (readline v3), "This is what we expect to see!\n", "v-strings even work in Mordor" );
+
+__DATA__
+This is what we expect to see!