use warnings;
use 5.010;
-my $IS_EBCDIC = ord ('A') == 193;
+BEGIN {
+ chdir 't' if -d 't';
+ require './test.pl';
+ skip_all_if_miniperl("no dynamic loading on miniperl, no File::Spec (used by charnames)");
+}
sub run_tests;
# It's ok to repeat class names.
#
InLatin1Supplement =>
- $IS_EBCDIC ? ['!\x{7f}', '\x{80}', '!\x{100}']
- : ['!\x{7f}', '\x{80}', '\x{ff}', '!\x{100}'],
+ ['!\N{U+7f}', '\N{U+80}', '\N{U+ff}', '!\x{100}'],
InLatinExtendedA =>
- ['!\x{7f}', '!\x{80}', '!\x{ff}', '\x{100}'],
+ ['!\N{U+7f}', '!\N{U+80}', '!\N{U+ff}', '\x{100}'],
#
# Properties are case-insensitive, and may have whitespace,
# dashes and underscores.
#
- 'in-latin1_SUPPLEMENT' => ['\x{80}',
+ 'in-latin1_SUPPLEMENT' => ['\N{U+80}',
'\N{LATIN SMALL LETTER Y WITH DIAERESIS}'],
' ^ In Latin 1 Supplement '
- => ['!\x{80}', '\N{COFFIN}'],
- 'latin-1 supplement' => ['\x{80}', "0xDF"],
+ => ['!\N{U+80}', '\N{COFFIN}'],
+ 'latin-1 supplement' => ['\N{U+80}', "0xDF"],
);
-my @USER_DEFINED_PROPERTIES = (
- #
- # User defined properties
- #
- InKana1 => ['\x{3040}', '!\x{303F}'],
- InKana2 => ['\x{3040}', '!\x{303F}'],
- InKana3 => ['\x{3041}', '!\x{3040}'],
- InNotKana => ['\x{3040}', '!\x{3041}'],
- InConsonant => ['d', '!e'],
- IsSyriac1 => ['\x{0712}', '!\x{072F}'],
- '# User-defined character properties may lack \n at the end',
- InGreekSmall => ['\N{GREEK SMALL LETTER PI}',
- '\N{GREEK SMALL LETTER FINAL SIGMA}'],
- InGreekCapital => ['\N{GREEK CAPITAL LETTER PI}', '!\x{03A2}'],
- Dash => ['-'],
- ASCII_Hex_Digit => ['!-', 'A'],
- IsAsciiHexAndDash => ['-', 'A'],
-);
-
-my @USER_CASELESS_PROPERTIES = (
- #
- # User defined properties which differ depending on /i. Second entry is
- # false regularly, true under /i
- #
- 'IsMyUpper' => ["M", "!m" ],
-);
+ my @USER_DEFINED_PROPERTIES = (
+ #
+ # User defined properties
+ #
+ InKana1 => ['\x{3040}', '!\x{303F}'],
+ InKana2 => ['\x{3040}', '!\x{303F}'],
+ InKana3 => ['\x{3041}', '!\x{3040}'],
+ InNotKana => ['\x{3040}', '!\x{3041}'],
+ InConsonant => ['d', '!e'],
+ IsSyriac1 => ['\x{0712}', '!\x{072F}'],
+ IsSyriac1KanaMark => ['\x{309A}', '!\x{3090}'],
+ IsSyriac1KanaMark => ['\x{0730}', '!\x{0712}'],
+ '# User-defined character properties may lack \n at the end',
+ InGreekSmall => ['\N{GREEK SMALL LETTER PI}',
+ '\N{GREEK SMALL LETTER FINAL SIGMA}'],
+ InGreekCapital => ['\N{GREEK CAPITAL LETTER PI}', '!\x{03A2}'],
+ Dash => ['-'],
+ ASCII_Hex_Digit => ['!-', 'A'],
+ IsAsciiHexAndDash => ['-', 'A'],
+
+ # This overrides the official one
+ InLatin1 => ['\x{0100}', '!\x{00FF}'],
+ );
+
+ my @USER_CASELESS_PROPERTIES = (
+ #
+ # User defined properties which differ depending on /i. Second entry
+ # is false normally, true under /i
+ #
+ 'IsMyUpper' => ["M", "!m" ],
+ );
#
push @{$d {IsWord}} => map {$class =~ /^[LMN]/ || $_ eq "_"
? $_ : "!$_"} @$chars;
push @{$d {IsSpace}} => map {$class =~ /^Z/ ||
- length ($_) == 1 && ord ($_) >= 0x09
- && ord ($_) <= 0x0D
+ length ($_) == 1 && utf8::native_to_unicode(ord ($_)) >= 0x09
+ && utf8::native_to_unicode(ord ($_)) <= 0x0D
? $_ : "!$_"} @$chars;
}
-delete $d {IsASCII} if $IS_EBCDIC;
-
push @CLASSES => "# Short properties" => %SHORT_PROPERTIES,
"# POSIX like properties" => %d,
"# User defined properties" => @USER_DEFINED_PROPERTIES;
my $count = 0;
for (my $i = 0; $i < @CLASSES; $i += 2) {
$i ++, redo if $CLASSES [$i] =~ /^\h*#\h*(.*)/;
- $count += (length $CLASSES [$i] == 1 ? 4 : 2) * @{$CLASSES [$i + 1]};
+ $count += 2 * (length $CLASSES [$i] == 1 ? 4 : 2) * @{$CLASSES [$i + 1]};
}
-$count += 2 * @ILLEGAL_PROPERTIES;
-$count += 2 * grep {length $_ == 1} @ILLEGAL_PROPERTIES;
-$count += 4 * @USER_CASELESS_PROPERTIES;
+$count += 4 * @ILLEGAL_PROPERTIES;
+$count += 4 * grep {length $_ == 1} @ILLEGAL_PROPERTIES;
+$count += 8 * @USER_CASELESS_PROPERTIES;
+$count += 1; # Test for pkg:IsMyLower
-my $tests = 0;
-
-say "1..$count";
+plan(tests => $count);
run_tests unless caller ();
my ($str, $name);
- given ($char) {
- when (/^\\/) {
- $str = eval qq ["$char"];
- $name = qq ["$char"];
- }
- when (/^0x([0-9A-Fa-f]+)$/) {
- $str = chr hex $1;
- $name = "chr ($char)";
- }
- default {
- $str = $char;
- $name = qq ["$char"];
- }
+ if ($char =~ /^\\/) {
+ $str = eval qq ["$char"];
+ $name = qq ["$char"];
+ }
+ elsif ($char =~ /^0x([0-9A-Fa-f]+)$/) {
+ $str = chr hex $1;
+ $name = "chr ($char)";
+ }
+ else {
+ $str = $char;
+ $name = qq ["$char"];
}
undef $@;
- my $match_pat = eval "qr/$match/$caseless";
- print "not " if $@ || ! ($str =~ /$match_pat/);
- print "ok ", ++ $tests, " - $name =~ $match_pat\n";
+ my $pat = "qr/$match/$caseless";
+ my $match_pat = eval $pat;
+ is($@, '', "$pat compiled correctly to a regexp: $@");
+ like($str, $match_pat, "$name correctly matched");
undef $@;
- my $nomatch_pat = eval "qr/$nomatch/$caseless";
- print "not " if $@ || ! ($str !~ /$nomatch_pat/);
- print "ok ", ++ $tests, " - $name !~ $nomatch_pat\n";
+ $pat = "qr/$nomatch/$caseless";
+ my $nomatch_pat = eval $pat;
+ is($@, '', "$pat compiled correctly to a regexp: $@");
+ unlike($str, $nomatch_pat, "$name correctly did not match");
}
sub run_tests {
}
- my $pat = qr /^Can't find Unicode property definition/;
print "# Illegal properties\n";
foreach my $p (@ILLEGAL_PROPERTIES) {
+ my $pat;
+ if ($p =~ /::/) {
+ $pat = qr /^Illegal user-defined property name/;
+ }
+ else {
+ $pat = qr /^Can't find Unicode property definition/;
+ }
+
undef $@;
my $r = eval "'a' =~ /\\p{$p}/; 1";
- print "not " unless !$r && $@ && $@ =~ $pat;
- print "ok ", ++ $tests, " - Unknown Unicode property \\p{$p}\n";
+ is($r, undef, "Unknown Unicode property \\p{$p}");
+ like($@, $pat, "Unknown Unicode property \\p{$p}");
undef $@;
my $s = eval "'a' =~ /\\P{$p}/; 1";
- print "not " unless !$s && $@ && $@ =~ $pat;
- print "ok ", ++ $tests, " - Unknown Unicode property \\P{$p}\n";
+ is($s, undef, "Unknown Unicode property \\p{$p}");
+ like($@, $pat, "Unknown Unicode property \\p{$p}");
if (length $p == 1) {
undef $@;
my $r = eval "'a' =~ /\\p$p/; 1";
- print "not " unless !$r && $@ && $@ =~ $pat;
- print "ok ", ++ $tests, " - Unknown Unicode property \\p$p\n";
+ is($r, undef, "Unknown Unicode property \\p$p");
+ like($@, $pat, "Unknown Unicode property \\p$p");
undef $@;
my $s = eval "'a' =~ /\\P$p/; 1";
- print "not " unless !$s && $@ && $@ =~ $pat;
- print "ok ", ++ $tests, " - Unknown Unicode property \\P$p\n";
+ is($r, undef, "Unknown Unicode property \\P$p");
+ like($@, $pat, "Unknown Unicode property \\P$p");
}
}
print "# User-defined properties with /i differences\n";
- foreach my $class (shift @USER_CASELESS_PROPERTIES) {
+ while (my $class = shift @USER_CASELESS_PROPERTIES) {
my $chars_ref = shift @USER_CASELESS_PROPERTIES;
my @in = grep {!/^!./} @$chars_ref;
my @out = map {s/^!(?=.)//; $_} grep { /^!./} @$chars_ref;
+utf8::IsCn
--
-sub InConsonant {<<'--'} # Not EBCDIC-aware.
-0061 007f
--0061
--0065
--0069
--006f
--0075
---
+sub InConsonant {
+
+ my $return = "+utf8::Lowercase\n&utf8::ASCII\n";
+ $return .= sprintf("-%X\n", ord "a");
+ $return .= sprintf("-%X\n", ord "e");
+ $return .= sprintf("-%X\n", ord "i");
+ $return .= sprintf("-%X\n", ord "o");
+ $return .= sprintf("-%X\n", ord "u");
+ return $return;
+}
sub IsSyriac1 {<<'--'}
0712 072C
+utf8::Dash
--
+sub InLatin1 {
+ return "0100\t10FFFF";
+}
+
sub IsMyUpper {
my $caseless = shift;
- if ($caseless) {
- return "0041\t005A\n0061\t007A"
- }
- else {
- return "0041\t005A"
- }
+ return "+utf8::"
+ . (($caseless)
+ ? 'Alphabetic'
+ : 'Uppercase')
+ . "\n&utf8::ASCII";
}
+{ # This has to be done here and not like the others, because we have to
+ # make sure that the property is not known until after the regex is
+ # compiled. It was previously getting confused about the pkg and /i
+ # combination
+
+ my $mylower = qr/\p{pkg::IsMyLower}/i;
+
+sub pkg::IsMyLower {
+ my $caseless = shift;
+ return "+utf8::"
+ . (($caseless)
+ ? 'Alphabetic'
+ : 'Lowercase')
+ . "\n&utf8::ASCII";
+}
+
+ like("A", $mylower, "Not available until runtime user-defined property with pkg:: and /i works");
+
+}
+
+# Verify that can use user-defined properties inside another one
+sub IsSyriac1KanaMark {<<'--'}
++main::IsSyriac1
++main::InKana3
+&utf8::IsMark
+--
+
# fake user-defined properties; these subs shouldn't be called, because
# their names don't start with In or Is
sub INfoo { die }
sub Is::foo { die }
sub In::foo { die }
+
+1;
__END__