source: trunk/essentials/dev-lang/perl/lib/utf8.t@ 3951

Last change on this file since 3951 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 15.0 KB
Line 
1#!./perl
2
3my $has_perlio;
4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8 require './test.pl';
9 unless ($has_perlio = find PerlIO::Layer 'perlio') {
10 print <<EOF;
11# Since you don't have perlio you might get failures with UTF-8 locales.
12EOF
13 }
14}
15
16no utf8; # Ironic, no?
17
18# NOTE!
19#
20# Think carefully before adding tests here. In general this should be
21# used only for about three categories of tests:
22#
23# (1) tests that absolutely require 'use utf8', and since that in general
24# shouldn't be needed as the utf8 is being obsoleted, this should
25# have rather few tests. If you want to test Unicode and regexes,
26# you probably want to go to op/regexp or op/pat; if you want to test
27# split, go to op/split; pack, op/pack; appending or joining,
28# op/append or op/join, and so forth
29#
30# (2) tests that have to do with Unicode tokenizing (though it's likely
31# that all the other Unicode tests sprinkled around the t/**/*.t are
32# going to catch that)
33#
34# (3) complicated tests that simultaneously stress so many Unicode features
35# that deciding into which other test script the tests should go to
36# is hard -- maybe consider breaking up the complicated test
37#
38#
39
40plan tests => 150;
41
42{
43 # bug id 20001009.001
44
45 my ($a, $b);
46
47 { use bytes; $a = "\xc3\xa4" }
48 { use utf8; $b = "\xe4" }
49
50 my $test = 68;
51
52 ok($a ne $b);
53
54 { use utf8; ok($a ne $b) }
55}
56
57
58{
59 # bug id 20000730.004
60
61 my $smiley = "\x{263a}";
62
63 for my $s ("\x{263a}",
64 $smiley,
65
66 "" . $smiley,
67 "" . "\x{263a}",
68
69 $smiley . "",
70 "\x{263a}" . "",
71 ) {
72 my $length_chars = length($s);
73 my $length_bytes;
74 { use bytes; $length_bytes = length($s) }
75 my @regex_chars = $s =~ m/(.)/g;
76 my $regex_chars = @regex_chars;
77 my @split_chars = split //, $s;
78 my $split_chars = @split_chars;
79 ok("$length_chars/$regex_chars/$split_chars/$length_bytes" eq
80 "1/1/1/3");
81 }
82
83 for my $s ("\x{263a}" . "\x{263a}",
84 $smiley . $smiley,
85
86 "\x{263a}\x{263a}",
87 "$smiley$smiley",
88
89 "\x{263a}" x 2,
90 $smiley x 2,
91 ) {
92 my $length_chars = length($s);
93 my $length_bytes;
94 { use bytes; $length_bytes = length($s) }
95 my @regex_chars = $s =~ m/(.)/g;
96 my $regex_chars = @regex_chars;
97 my @split_chars = split //, $s;
98 my $split_chars = @split_chars;
99 ok("$length_chars/$regex_chars/$split_chars/$length_bytes" eq
100 "2/2/2/6");
101 }
102}
103
104
105{
106 my $w = 0;
107 local $SIG{__WARN__} = sub { print "#($_[0])\n"; $w++ };
108 my $x = eval q/"\\/ . "\x{100}" . q/"/;;
109
110 ok($w == 0 && $x eq "\x{100}");
111}
112
113{
114 use warnings;