Add back the new casing tests.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 19 Feb 2002 03:49:34 +0000 (03:49 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 19 Feb 2002 03:49:34 +0000 (03:49 +0000)
p4raw-id: //depot/perl@14761

MANIFEST
t/uni/case.pl [new file with mode: 0644]
t/uni/lower.t [new file with mode: 0644]
t/uni/title.t [new file with mode: 0644]
t/uni/upper.t [new file with mode: 0644]

index a2ac823..36326fd 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2409,8 +2409,12 @@ t/run/switchx.t                 Test the -x switch
 t/TEST                         The regression tester
 t/test.pl                      Simple testing library
 t/TestInit.pm                  Preamble library for core tests
+t/uni/case.pl                  See if Unicode casing works
 t/uni/fold.t                   See if Unicode folding works
+t/uni/lower.t                  See if Unicode casing works
 t/uni/sprintf.t                        See if Unicode sprintf works
+t/uni/title.t                  See if Unicode casing works
+t/uni/upper.t                  See if Unicode casing works
 taint.c                                Tainting code
 thrdvar.h                      Per-thread variables
 thread.h                       Threading header
diff --git a/t/uni/case.pl b/t/uni/case.pl
new file mode 100644 (file)
index 0000000..f5c4f78
--- /dev/null
@@ -0,0 +1,80 @@
+use File::Spec;
+
+require "test.pl";
+
+sub casetest {
+    my ($base, $spec, $func) = @_;
+    my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir,
+                                                     "lib", "unicore", "To"),
+                                  "$base.pl");
+    my $simple = do $file;
+    my %simple;
+    for my $i (split(/\n/, $simple)) {
+       my ($k, $v) = split(' ', $i);
+       $simple{$k} = $v;
+    }
+    my %seen;
+
+    for my $i (sort keys %simple) {
+       $seen{hex $i}++;
+    }
+    print "# ", scalar keys %simple, " simple mappings\n";
+
+    my $both;
+
+    for my $i (sort keys %$spec) {
+       if (++$seen{hex $i} == 2) {
+           warn "$base: $i seen twice\n";
+           $both++;
+       }
+    }
+    print "# ", scalar keys %$spec, " special mappings\n";
+
+    exit(1) if $both;
+
+    my %none;
+    for my $i (map { ord } split //,
+              "\e !\"#\$%&'()+,-./0123456789:;<=>?\@[\\]^_{|}~\b") {
+       next if pack("U0U", $i) =~ /\w/;
+       $none{$i}++ unless $seen{$i};
+    }
+    print "# ", scalar keys %none, " noncase mappings\n";
+
+    my $tests = 
+       (scalar keys %simple) +
+       (scalar keys %$spec) +
+       (scalar keys %none);
+    print "1..$tests\n";
+
+    my $test = 1;
+
+    for my $i (sort { hex $a <=> hex $b } keys %simple) {
+       my $w = "$i -> $simple{$i}";
+       my $c = pack "U0U", hex $i;
+       my $d = $func->($c);
+       print $d eq pack("U0U", hex $simple{$i}) ?
+           "ok $test # $w\n" : "not ok $test # $w\n";
+       $test++;
+    }
+
+    for my $i (sort { hex $a <=> hex $b } keys %$spec) {
+       my $w = qq[$i -> "] . display($spec->{$i}) . qq["];
+       my $c = pack "U0U", hex $i;
+       my $d = $func->($c);
+       print $d eq $spec->{$i} ?
+           "ok $test # $w\n" : "not ok $test # $w\n";
+       $test++;
+    }
+
+
+    for my $i (sort { $a <=> $b } keys %none) {
+       my $w = sprintf "%04X -> %04X", $i, $i;
+       my $c = pack "U0U", $i;
+       my $d = $func->($c);
+       print $d eq $c ?
+           "ok $test # $w\n" : "not ok $test # $w\n";
+       $test++;
+    }
+}
+
+1;
diff --git a/t/uni/lower.t b/t/uni/lower.t
new file mode 100644 (file)
index 0000000..4420d0b
--- /dev/null
@@ -0,0 +1,8 @@
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(../lib uni .);
+    require "case.pl";
+}
+
+casetest("Lower", \%utf8::ToSpecLower, sub { lc $_[0] });
+
diff --git a/t/uni/title.t b/t/uni/title.t
new file mode 100644 (file)
index 0000000..c0b7e3a
--- /dev/null
@@ -0,0 +1,8 @@
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(../lib uni .);
+    require "case.pl";
+}
+
+casetest("Title", \%utf8::ToSpecTitle, sub { ucfirst $_[0] });
+
diff --git a/t/uni/upper.t b/t/uni/upper.t
new file mode 100644 (file)
index 0000000..5694c26
--- /dev/null
@@ -0,0 +1,8 @@
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(../lib uni .);
+    require "case.pl";
+}
+
+casetest("Upper", \%utf8::ToSpecUpper, sub { uc $_[0] });
+