1*0Sstevel@tonic-gate#!./perl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = qw(../lib .); 6*0Sstevel@tonic-gate require "test.pl"; 7*0Sstevel@tonic-gate} 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gateplan tests => 25; 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate$a = "B\x{fc}f"; 12*0Sstevel@tonic-gate$b = "G\x{100}r"; 13*0Sstevel@tonic-gate$c = 0x200; 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gate{ 16*0Sstevel@tonic-gate my $s = sprintf "%s", $a; 17*0Sstevel@tonic-gate is($s, $a, "%s a"); 18*0Sstevel@tonic-gate} 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate{ 21*0Sstevel@tonic-gate my $s = sprintf "%s", $b; 22*0Sstevel@tonic-gate is($s, $b, "%s b"); 23*0Sstevel@tonic-gate} 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate{ 26*0Sstevel@tonic-gate my $s = sprintf "%s%s", $a, $b; 27*0Sstevel@tonic-gate is($s, $a.$b, "%s%s a b"); 28*0Sstevel@tonic-gate} 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate{ 31*0Sstevel@tonic-gate my $s = sprintf "%s%s", $b, $a; 32*0Sstevel@tonic-gate is($s, $b.$a, "%s%s b a"); 33*0Sstevel@tonic-gate} 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate{ 36*0Sstevel@tonic-gate my $s = sprintf "%s%s", $b, $b; 37*0Sstevel@tonic-gate is($s, $b.$b, "%s%s b b"); 38*0Sstevel@tonic-gate} 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate{ 41*0Sstevel@tonic-gate my $s = sprintf "%s$b", $a; 42*0Sstevel@tonic-gate is($s, $a.$b, "%sb a"); 43*0Sstevel@tonic-gate} 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate{ 46*0Sstevel@tonic-gate my $s = sprintf "$b%s", $a; 47*0Sstevel@tonic-gate is($s, $b.$a, "b%s a"); 48*0Sstevel@tonic-gate} 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate{ 51*0Sstevel@tonic-gate my $s = sprintf "%s$a", $b; 52*0Sstevel@tonic-gate is($s, $b.$a, "%sa b"); 53*0Sstevel@tonic-gate} 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate{ 56*0Sstevel@tonic-gate my $s = sprintf "$a%s", $b; 57*0Sstevel@tonic-gate is($s, $a.$b, "a%s b"); 58*0Sstevel@tonic-gate} 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate{ 61*0Sstevel@tonic-gate my $s = sprintf "$a%s", $a; 62*0Sstevel@tonic-gate is($s, $a.$a, "a%s a"); 63*0Sstevel@tonic-gate} 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate{ 66*0Sstevel@tonic-gate my $s = sprintf "$b%s", $b; 67*0Sstevel@tonic-gate is($s, $b.$b, "a%s b"); 68*0Sstevel@tonic-gate} 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate{ 71*0Sstevel@tonic-gate my $s = sprintf "%c", $c; 72*0Sstevel@tonic-gate is($s, chr($c), "%c c"); 73*0Sstevel@tonic-gate} 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate{ 76*0Sstevel@tonic-gate my $s = sprintf "%s%c", $a, $c; 77*0Sstevel@tonic-gate is($s, $a.chr($c), "%s%c a c"); 78*0Sstevel@tonic-gate} 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate{ 81*0Sstevel@tonic-gate my $s = sprintf "%c%s", $c, $a; 82*0Sstevel@tonic-gate is($s, chr($c).$a, "%c%s c a"); 83*0Sstevel@tonic-gate} 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate{ 86*0Sstevel@tonic-gate my $s = sprintf "%c$b", $c; 87*0Sstevel@tonic-gate is($s, chr($c).$b, "%cb c"); 88*0Sstevel@tonic-gate} 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate{ 91*0Sstevel@tonic-gate my $s = sprintf "%s%c$b", $a, $c; 92*0Sstevel@tonic-gate is($s, $a.chr($c).$b, "%s%cb a c"); 93*0Sstevel@tonic-gate} 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate{ 96*0Sstevel@tonic-gate my $s = sprintf "%c%s$b", $c, $a; 97*0Sstevel@tonic-gate is($s, chr($c).$a.$b, "%c%sb c a"); 98*0Sstevel@tonic-gate} 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate{ 101*0Sstevel@tonic-gate my $s = sprintf "$b%c", $c; 102*0Sstevel@tonic-gate is($s, $b.chr($c), "b%c c"); 103*0Sstevel@tonic-gate} 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate{ 106*0Sstevel@tonic-gate my $s = sprintf "$b%s%c", $a, $c; 107*0Sstevel@tonic-gate is($s, $b.$a.chr($c), "b%s%c a c"); 108*0Sstevel@tonic-gate} 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate{ 111*0Sstevel@tonic-gate my $s = sprintf "$b%c%s", $c, $a; 112*0Sstevel@tonic-gate is($s, $b.chr($c).$a, "b%c%s c a"); 113*0Sstevel@tonic-gate} 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate{ 116*0Sstevel@tonic-gate # 20010407.008 sprintf removes utf8-ness 117*0Sstevel@tonic-gate $a = sprintf "\x{1234}"; 118*0Sstevel@tonic-gate is((sprintf "%x %d", unpack("U*", $a), length($a)), "1234 1", 119*0Sstevel@tonic-gate '\x{1234}'); 120*0Sstevel@tonic-gate $a = sprintf "%s", "\x{5678}"; 121*0Sstevel@tonic-gate is((sprintf "%x %d", unpack("U*", $a), length($a)), "5678 1", 122*0Sstevel@tonic-gate '%s \x{5678}'); 123*0Sstevel@tonic-gate $a = sprintf "\x{1234}%s", "\x{5678}"; 124*0Sstevel@tonic-gate is((sprintf "%x %x %d", unpack("U*", $a), length($a)), "1234 5678 2", 125*0Sstevel@tonic-gate '\x{1234}%s \x{5678}'); 126*0Sstevel@tonic-gate} 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate{ 129*0Sstevel@tonic-gate # check that utf8ness doesn't "accumulate" 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate my $w = "w\x{fc}"; 132*0Sstevel@tonic-gate my $sprintf; 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate $sprintf = sprintf "%s%s", $w, "$w\x{100}"; 135*0Sstevel@tonic-gate is(substr($sprintf,0,2), $w, "utf8 echo"); 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate $sprintf = sprintf "%s%s", $w, "$w\x{100}"; 138*0Sstevel@tonic-gate is(substr($sprintf,0,2), $w, "utf8 echo echo"); 139*0Sstevel@tonic-gate} 140