This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make $class->method work when $class is tied
[perl5.git] / t / uni / class.t
CommitLineData
0f1b7392
RGS
1BEGIN {
2 chdir 't' if -d 't';
3 @INC = qw(../lib .);
4 require "test.pl";
5}
6
99870f4d 7plan tests => 10;
0f1b7392 8
d658a8a8 9sub IsMyUniClass {
0f1b7392
RGS
10 <<END;
110030 004F
12END
13}
14
d658a8a8 15sub Other::IsClass {
0f1b7392
RGS
16 <<END;
170040 005F
18END
19}
20
21sub A::B::Intersection {
22 <<END;
d658a8a8
DM
23+main::IsMyUniClass
24&Other::IsClass
0f1b7392
RGS
25END
26}
27
cd1c2c69
T
28sub test_regexp ($$) {
29 # test that given string consists of N-1 chars matching $qr1, and 1
30 # char matching $qr2
31 my ($str, $blk) = @_;
32
33 # constructing these objects here makes the last test loop go much faster
34 my $qr1 = qr/(\p{$blk}+)/;
35 if ($str =~ $qr1) {
36 is($1, substr($str, 0, -1)); # all except last char
37 }
38 else {
39 fail('first N-1 chars did not match');
40 }
41
42 my $qr2 = qr/(\P{$blk}+)/;
43 if ($str =~ $qr2) {
44 is($1, substr($str, -1)); # only last char
45 }
46 else {
47 fail('last char did not match');
48 }
49}
50
51use strict;
0f1b7392 52
8a38a836 53my $str = join "", map latin1_to_native(chr($_)), 0x20 .. 0x6F;
0f1b7392
RGS
54
55# make sure it finds built-in class
56is(($str =~ /(\p{Letter}+)/)[0], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
12ac2576 57is(($str =~ /(\p{l}+)/)[0], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
0f1b7392
RGS
58
59# make sure it finds user-defined class
d658a8a8 60is(($str =~ /(\p{IsMyUniClass}+)/)[0], '0123456789:;<=>?@ABCDEFGHIJKLMNO');
0f1b7392
RGS
61
62# make sure it finds class in other package
d658a8a8 63is(($str =~ /(\p{Other::IsClass}+)/)[0], '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_');
0f1b7392
RGS
64
65# make sure it finds class in other OTHER package
66is(($str =~ /(\p{A::B::Intersection}+)/)[0], '@ABCDEFGHIJKLMNO');
12ac2576 67
484741e1
KW
68# lib/unicore/lib/Bc/AL.pl. U+070E is unassigned, currently, but still has
69# bidi class AL. The first one in the sequence that doesn't is 0711, which is
70# BC=NSM.
71$str = "\x{070D}\x{070E}\x{070F}\x{0710}\x{0711}\x{0712}";
72is(($str =~ /(\P{BidiClass: ArabicLetter}+)/)[0], "\x{0711}");
73is(($str =~ /(\P{BidiClass: AL}+)/)[0], "\x{0711}");
74is(($str =~ /(\P{BC :ArabicLetter}+)/)[0], "\x{0711}");
75is(($str =~ /(\P{bc=AL}+)/)[0], "\x{0711}");
12ac2576
JP
76
77# make sure InGreek works
78$str = "[\x{038B}\x{038C}\x{038D}]";
79
80is(($str =~ /(\p{InGreek}+)/)[0], "\x{038B}\x{038C}\x{038D}");
cd1c2c69 81
99870f4d 82# The other tests that are based on looking at the generated files are now
3df51b85 83# in t/re/uniprops.t