develooper Front page | perl.perl5.porters | Postings from September 2000

[PATCH: perl@7094] a possible way to test 8 bit concat && de-utf8ing

From:
Peter Prymmer
Date:
September 27, 2000 19:30
Subject:
[PATCH: perl@7094] a possible way to test 8 bit concat && de-utf8ing
Message ID:
Pine.OSF.4.10.10009271914480.5923-100000@aspara.forte.com

Drawing inspiration from Nick's message in:

 http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-09/msg01141.html

I've put together a minor modification to one of the regression tests.

I am not sure if this is the correct test to place this mod into (perhaps
it ought to be in a new t/pragma/bytes.t test?), nor have I given much
thought to the ramifications of placing a C<use bytes;> pragma in this
particular test, but here it is anyway:

--- t/op/append.t.orig	Thu Sep 14 18:55:07 2000
+++ t/op/append.t	Wed Sep 27 19:21:50 2000
@@ -2,7 +2,12 @@
 
 # $RCSfile: append.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:36 $
 
-print "1..13\n";
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+}
+
+print "1..15\n";
 
 $a = 'ab' . 'c';	# compile time
 $b = 'def';
@@ -54,3 +59,28 @@
     my $t8 = $u; $t8 = $ub . $t8;
     print $t8 =~ /b/ ? "ok 13\n" : "not ok 13\t# $t8\n";
 }
+
+# Test that utf8-ification can be done/undone with 7 or 8 bit input data.
+sub fudge
+{
+    my $data = $_[0].chr(256); # Something that UTF8s the data.
+    chop($data);
+    $data =~ s/^\w+\s+//;
+    $data = 'Want '.$data;
+    return $data;
+}
+# 8 bit test.
+{
+    use bytes;
+    my $data = "Want 25\xA2 or \xA3100?"; # cents and pounds in ISO 8859-1
+                                          # 's' and 't' in most EBCDIC
+    my $fudge = fudge($data);
+    print $data eq $fudge ? "ok 14\n" : "not ok 14\t# $data ne $fudge\n";
+}
+# 7 bit test (on ASCIIish machines at least).
+{
+    use bytes;
+    my $data = 'Want 25 or 100?';
+    my $fudge = fudge($data);
+    print $data eq $fudge ? "ok 15\n" : "not ok 15\t# $data ne $fudge\n";
+}
End of Patch.

Do note that this intentionally introduces a new failure. On Digital Unix
4.0D I now see:

op/64bitint..........ok
op/append............FAILED at test 14
op/args..............ok

Failed 1 test script out of 259, 99.61% okay.

under `make test`.

Peter Prymmer






nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About