1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate# tests 51 onwards aren't all warnings clean. (intentionally) 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gateprint "1..71\n"; 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gatemy $test = 1; 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gatesub test ($$$) { 10*0Sstevel@tonic-gate my ($act, $string, $value) = @_; 11*0Sstevel@tonic-gate my $result; 12*0Sstevel@tonic-gate if ($act eq 'oct') { 13*0Sstevel@tonic-gate $result = oct $string; 14*0Sstevel@tonic-gate } elsif ($act eq 'hex') { 15*0Sstevel@tonic-gate $result = hex $string; 16*0Sstevel@tonic-gate } else { 17*0Sstevel@tonic-gate die "Unknown action 'act'"; 18*0Sstevel@tonic-gate } 19*0Sstevel@tonic-gate if ($value == $result) { 20*0Sstevel@tonic-gate if ($^O eq 'VMS' && length $string > 256) { 21*0Sstevel@tonic-gate $string = ''; 22*0Sstevel@tonic-gate } else { 23*0Sstevel@tonic-gate $string = "\"$string\""; 24*0Sstevel@tonic-gate } 25*0Sstevel@tonic-gate print "ok $test # $act $string\n"; 26*0Sstevel@tonic-gate } else { 27*0Sstevel@tonic-gate my ($valstr, $resstr); 28*0Sstevel@tonic-gate if ($act eq 'hex' or $string =~ /x/) { 29*0Sstevel@tonic-gate $valstr = sprintf "0x%X", $value; 30*0Sstevel@tonic-gate $resstr = sprintf "0x%X", $result; 31*0Sstevel@tonic-gate } elsif ($string =~ /b/) { 32*0Sstevel@tonic-gate $valstr = sprintf "0b%b", $value; 33*0Sstevel@tonic-gate $resstr = sprintf "0b%b", $result; 34*0Sstevel@tonic-gate } else { 35*0Sstevel@tonic-gate $valstr = sprintf "0%o", $value; 36*0Sstevel@tonic-gate $resstr = sprintf "0%o", $result; 37*0Sstevel@tonic-gate } 38*0Sstevel@tonic-gate print "not ok $test # $act \"$string\" gives \"$result\" ($resstr), not $value ($valstr)\n"; 39*0Sstevel@tonic-gate } 40*0Sstevel@tonic-gate $test++; 41*0Sstevel@tonic-gate} 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gatetest ('oct', '0b1_0101', 0b101_01); 44*0Sstevel@tonic-gatetest ('oct', '0b10_101', 0_2_5); 45*0Sstevel@tonic-gatetest ('oct', '0b101_01', 2_1); 46*0Sstevel@tonic-gatetest ('oct', '0b1010_1', 0x1_5); 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gatetest ('oct', 'b1_0101', 0b10101); 49*0Sstevel@tonic-gatetest ('oct', 'b10_101', 025); 50*0Sstevel@tonic-gatetest ('oct', 'b101_01', 21); 51*0Sstevel@tonic-gatetest ('oct', 'b1010_1', 0x15); 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gatetest ('oct', '01_234', 0b10_1001_1100); 54*0Sstevel@tonic-gatetest ('oct', '012_34', 01234); 55*0Sstevel@tonic-gatetest ('oct', '0123_4', 668); 56*0Sstevel@tonic-gatetest ('oct', '01234', 0x29c); 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gatetest ('oct', '0x1_234', 0b10010_00110100); 59*0Sstevel@tonic-gatetest ('oct', '0x12_34', 01_1064); 60*0Sstevel@tonic-gatetest ('oct', '0x123_4', 4660); 61*0Sstevel@tonic-gatetest ('oct', '0x1234', 0x12_34); 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gatetest ('oct', 'x1_234', 0b100100011010_0); 64*0Sstevel@tonic-gatetest ('oct', 'x12_34', 0_11064); 65*0Sstevel@tonic-gatetest ('oct', 'x123_4', 4660); 66*0Sstevel@tonic-gatetest ('oct', 'x1234', 0x_1234); 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gatetest ('hex', '01_234', 0b_1001000110100); 69*0Sstevel@tonic-gatetest ('hex', '012_34', 011064); 70*0Sstevel@tonic-gatetest ('hex', '0123_4', 4660); 71*0Sstevel@tonic-gatetest ('hex', '01234_', 0x1234); 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gatetest ('hex', '0x_1234', 0b1001000110100); 74*0Sstevel@tonic-gatetest ('hex', '0x1_234', 011064); 75*0Sstevel@tonic-gatetest ('hex', '0x12_34', 4660); 76*0Sstevel@tonic-gatetest ('hex', '0x1234_', 0x1234); 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gatetest ('hex', 'x_1234', 0b1001000110100); 79*0Sstevel@tonic-gatetest ('hex', 'x12_34', 011064); 80*0Sstevel@tonic-gatetest ('hex', 'x123_4', 4660); 81*0Sstevel@tonic-gatetest ('hex', 'x1234_', 0x1234); 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gatetest ('oct', '0b1111_1111_1111_1111_1111_1111_1111_1111', 4294967295); 84*0Sstevel@tonic-gatetest ('oct', '037_777_777_777', 4294967295); 85*0Sstevel@tonic-gatetest ('oct', '0xffff_ffff', 4294967295); 86*0Sstevel@tonic-gatetest ('hex', '0xff_ff_ff_ff', 4294967295); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate$_ = "\0_7_7"; 89*0Sstevel@tonic-gateprint length eq 5 ? "ok" : "not ok", " 37\n"; 90*0Sstevel@tonic-gateprint $_ eq "\0"."_"."7"."_"."7" ? "ok" : "not ok", " 38\n"; 91*0Sstevel@tonic-gatechop, chop, chop, chop; 92*0Sstevel@tonic-gateprint $_ eq "\0" ? "ok" : "not ok", " 39\n"; 93*0Sstevel@tonic-gateif (ord("\t") != 9) { 94*0Sstevel@tonic-gate # question mark is 111 in 1047, 037, && POSIX-BC 95*0Sstevel@tonic-gate print "\157_" eq "?_" ? "ok" : "not ok", " 40\n"; 96*0Sstevel@tonic-gate} 97*0Sstevel@tonic-gateelse { 98*0Sstevel@tonic-gate print "\077_" eq "?_" ? "ok" : "not ok", " 40\n"; 99*0Sstevel@tonic-gate} 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate$_ = "\x_7_7"; 102*0Sstevel@tonic-gateprint length eq 5 ? "ok" : "not ok", " 41\n"; 103*0Sstevel@tonic-gateprint $_ eq "\0"."_"."7"."_"."7" ? "ok" : "not ok", " 42\n"; 104*0Sstevel@tonic-gatechop, chop, chop, chop; 105*0Sstevel@tonic-gateprint $_ eq "\0" ? "ok" : "not ok", " 43\n"; 106*0Sstevel@tonic-gateif (ord("\t") != 9) { 107*0Sstevel@tonic-gate # / is 97 in 1047, 037, && POSIX-BC 108*0Sstevel@tonic-gate print "\x61_" eq "/_" ? "ok" : "not ok", " 44\n"; 109*0Sstevel@tonic-gate} 110*0Sstevel@tonic-gateelse { 111*0Sstevel@tonic-gate print "\x2F_" eq "/_" ? "ok" : "not ok", " 44\n"; 112*0Sstevel@tonic-gate} 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate$test = 45; 115*0Sstevel@tonic-gatetest ('oct', '0b'.( '0'x10).'1_0101', 0b101_01); 116*0Sstevel@tonic-gatetest ('oct', '0b'.( '0'x100).'1_0101', 0b101_01); 117*0Sstevel@tonic-gatetest ('oct', '0b'.('0'x1000).'1_0101', 0b101_01); 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gatetest ('hex', ( '0'x10).'01234', 0x1234); 120*0Sstevel@tonic-gatetest ('hex', ( '0'x100).'01234', 0x1234); 121*0Sstevel@tonic-gatetest ('hex', ('0'x1000).'01234', 0x1234); 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate# Things that perl 5.6.1 and 5.7.2 did wrong (plus some they got right) 124*0Sstevel@tonic-gatetest ('oct', "b00b0101", 0); 125*0Sstevel@tonic-gatetest ('oct', "bb0101", 0); 126*0Sstevel@tonic-gatetest ('oct', "0bb0101", 0); 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gatetest ('oct', "0x0x3A", 0); 129*0Sstevel@tonic-gatetest ('oct', "0xx3A", 0); 130*0Sstevel@tonic-gatetest ('oct', "x0x3A", 0); 131*0Sstevel@tonic-gatetest ('oct', "xx3A", 0); 132*0Sstevel@tonic-gatetest ('oct', "0x3A", 0x3A); 133*0Sstevel@tonic-gatetest ('oct', "x3A", 0x3A); 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gatetest ('oct', "0x0x4", 0); 136*0Sstevel@tonic-gatetest ('oct', "0xx4", 0); 137*0Sstevel@tonic-gatetest ('oct', "x0x4", 0); 138*0Sstevel@tonic-gatetest ('oct', "xx4", 0); 139*0Sstevel@tonic-gatetest ('oct', "0x4", 4); 140*0Sstevel@tonic-gatetest ('oct', "x4", 4); 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gatetest ('hex', "0x3A", 0x3A); 143*0Sstevel@tonic-gatetest ('hex', "x3A", 0x3A); 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gatetest ('hex', "0x4", 4); 146*0Sstevel@tonic-gatetest ('hex', "x4", 4); 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gateeval '$a = oct "10\x{100}"'; 149*0Sstevel@tonic-gateprint $@ =~ /Wide character/ ? "ok $test\n" : "not ok $test\n"; $test++; 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gateeval '$a = hex "ab\x{100}"'; 152*0Sstevel@tonic-gateprint $@ =~ /Wide character/ ? "ok $test\n" : "not ok $test\n"; $test++; 153