From 80a5d8e74b5512d4ab704d0e83466ae41247ce55 Mon Sep 17 00:00:00 2001 From: Nick Ing-Simmons Date: Mon, 8 Apr 2002 07:28:27 +0000 Subject: Integrate mainline p4raw-id: //depot/perlio@15801 --- t/op/readdir.t | 24 ++++++++++++- t/op/utfhash.t | 104 +++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 110 insertions(+), 18 deletions(-) (limited to 't/op') diff --git a/t/op/readdir.t b/t/op/readdir.t index 7cfecdb565..8e67b65da6 100755 --- a/t/op/readdir.t +++ b/t/op/readdir.t @@ -8,7 +8,7 @@ BEGIN { eval 'opendir(NOSUCH, "no/such/directory");'; if ($@) { print "1..0\n"; exit; } -print "1..3\n"; +print "1..6\n"; for $i (1..2000) { local *OP; @@ -43,3 +43,25 @@ while (@R && @G && "op/".$R[0] eq $G[0]) { shift(@G); } if (@R == 0 && @G == 0) { print "ok 3\n"; } else { print "not ok 3\n"; } + +# Can't really depend on Tru64 UTF-8 filenames being so must just see +# that things don't crash and that *if* UTF-8 were to be received, it's +# valid. (Maybe later add checks that are run if we are on NTFS/HFS+.) +# (see also ext/File/Glob/t/utf8.t) + +opendir(OP, ":utf8", "op"); + +my $a = readdir(OP); + +print utf8::valid($a) ? "ok 4\n" : "not ok 4\n"; + +my @a = readdir(OP); + +print utf8::valid($a[0]) ? "ok 5\n" : "not ok 5\n"; + +# But we can check for bogus mode arguments. + +eval { opendir(OP, ":foo", "op") }; + +print $@ =~ /Unknown discipline ':foo'/ ? "ok 6\n" : "not ok 6\n"; + diff --git a/t/op/utfhash.t b/t/op/utfhash.t index e2337e0785..af7e6c1296 100644 --- a/t/op/utfhash.t +++ b/t/op/utfhash.t @@ -1,11 +1,15 @@ +#!./perl -w + BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require './test.pl'; - plan(tests => 48); + plan(tests => 91); } +use strict; + # Two hashes one will all keys 8-bit possible (initially), other # with a utf8 requiring key from the outset. @@ -79,24 +83,90 @@ foreach my $a ("\x7f","\xff") { - print "# Unicode hash keys and \\w\n"; - # This is not really a regex test but regexes bring - # out the issue nicely. - use strict; - my $u3 = "f\x{df}\x{100}"; - my $u2 = substr($u3,0,2); - my $u1 = substr($u2,0,1); - my %u = ( $u1 => $u1, $u2 => $u2, $u3 => $u3 ); + print "# Unicode hash keys and \\w\n"; + # This is not really a regex test but regexes bring + # out the issue nicely. + use strict; + my $u3 = "f\x{df}\x{100}"; + my $u2 = substr($u3,0,2); + my $u1 = substr($u2,0,1); + my $u0 = chr (0xdf)x4; # Make this 4 chars so that all lengths are distinct. + + my @u = ($u0, $u1, $u2, $u3); + + while (@u) { + my %u = (map {( $_, $_)} @u); + my $keys = scalar @u; + $keys .= ($keys == 1) ? " key" : " keys"; for (keys %u) { - ok (/^\w+$/ && $u{$_} =~ /^\w+$/, "\\w on keys"); - } - - for (each %u) { - ok (/^\w+$/ && $u{$_} =~ /^\w+$/, "\\w on each"); - } + my $l = 0 + /^\w+$/; + my $r = 0 + $u{$_} =~ /^\w+$/; + is ($l, $r, "\\w on keys with $keys, key of length " . length $_); + } + + my $more; + do { + $more = 0; + # Want to do this direct, rather than copying to a temporary variable + # The first time each will return key and value at the start of the hash. + # each will return () after we've done the last pair. $more won't get + # set then, and the do will exit. + for (each %u) { + $more = 1; + my $l = 0 + /^\w+$/; + my $r = 0 + $u{$_} =~ /^\w+$/; + is ($l, $r, "\\w on each, with $keys, key of length " . length $_); + } + } while ($more); for (%u) { - ok (/^\w+$/ && $u{$_} =~ /^\w+$/, "\\w on hash"); - } + my $l = 0 + /^\w+$/; + my $r = 0 + $u{$_} =~ /^\w+$/; + is ($l, $r, "\\w on hash with $keys, key of length " . length $_); + } + pop @u; + undef %u; + } +} + +{ + my $utf8_sz = my $bytes_sz = "\x{df}"; + $utf8_sz .= chr 256; + chop ($utf8_sz); + + my (%bytes_first, %utf8_first); + + $bytes_first{$bytes_sz} = $bytes_sz; + + for (keys %bytes_first) { + my $l = 0 + /^\w+$/; + my $r = 0 + $bytes_first{$_} =~ /^\w+$/; + is ($l, $r, "\\w on each, bytes"); + } + + $bytes_first{$utf8_sz} = $utf8_sz; + + for (keys %bytes_first) { + my $l = 0 + /^\w+$/; + my $r = 0 + $bytes_first{$_} =~ /^\w+$/; + is ($l, $r, "\\w on each, bytes now utf8"); + } + + $utf8_first{$utf8_sz} = $utf8_sz; + + for (keys %utf8_first) { + my $l = 0 + /^\w+$/; + my $r = 0 + $utf8_first{$_} =~ /^\w+$/; + is ($l, $r, "\\w on each, utf8"); + } + + $utf8_first{$bytes_sz} = $bytes_sz; + + for (keys %utf8_first) { + my $l = 0 + /^\w+$/; + my $r = 0 + $utf8_first{$_} =~ /^\w+$/; + is ($l, $r, "\\w on each, utf8 now bytes"); + } + } -- cgit v1.2.1