1 ################################################################################
3 # !!!!! Do NOT edit this file directly! !!!!!
5 # Edit mktests.PL and/or parts/inc/utf8 instead.
7 # This file was automatically generated from the definition files in the
8 # parts/inc/ subdirectory by mktests.PL. To learn more about how all this
9 # works, please read the F<HACKERS> file that came with this distribution.
11 ################################################################################
14 if ($ENV{'PERL_CORE'}) {
16 @INC = ('../lib', '../ext/Devel-PPPort/t') if -d '../lib' && -d '../ext';
17 require Config; import Config;
19 if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
30 require 'testutil.pl' if $@;
43 package Devel::PPPort;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
51 BEGIN { require warnings if "$]" gt '5.006' }
53 # skip tests on 5.6.0 and earlier
54 if ("$]" le '5.006') {
55 skip 'skip: broken utf8 support', 0 for 1..58;
59 ok(&Devel::PPPort::UTF8_SAFE_SKIP("A", 0), 1);
60 ok(&Devel::PPPort::UTF8_SAFE_SKIP("A", -1), 0);
62 ok(&Devel::PPPort::isUTF8_CHAR("A", -1), 0);
63 ok(&Devel::PPPort::isUTF8_CHAR("A", 0), 1);
64 ok(&Devel::PPPort::isUTF8_CHAR("\x{100}", -1), 0);
65 ok(&Devel::PPPort::isUTF8_CHAR("\x{100}", 0), 2);
67 if ("$]" lt '5.008') {
71 ok(&Devel::PPPort::foldEQ_utf8("A\x{100}", 3, 1, "a\x{101}", 3, 1), 1);
72 ok(&Devel::PPPort::foldEQ_utf8("A\x{100}", 3, 1, "a\x{102}", 3, 1), 0);
73 ok(&Devel::PPPort::foldEQ_utf8("A\x{100}", 3, 1, "b\x{101}", 3, 1), 0);
76 my $ret = &Devel::PPPort::utf8_to_uvchr("A");
77 ok($ret->[0], ord("A"));
80 $ret = &Devel::PPPort::utf8_to_uvchr("\0");
84 $ret = &Devel::PPPort::utf8_to_uvchr_buf("A", 0);
85 ok($ret->[0], ord("A"));
88 $ret = &Devel::PPPort::utf8_to_uvchr_buf("\0", 0);
92 if (ord("A") != 65) { # tests not valid for EBCDIC
93 ok(1, 1) for 1 .. (2 + 4 + (7 * 5));
96 $ret = &Devel::PPPort::utf8_to_uvchr_buf("\xc4\x80", 0);
101 local $SIG{__WARN__} = sub { push @warnings, @_; };
104 BEGIN { 'warnings'->import('utf8') if "$]" gt '5.006' }
105 $ret = &Devel::PPPort::utf8_to_uvchr("\xe0\0\x80");
109 BEGIN { 'warnings'->unimport() if "$]" gt '5.006' }
110 $ret = &Devel::PPPort::utf8_to_uvchr("\xe0\0\x80");
111 ok($ret->[0], 0xFFFD);
119 warning => qr/empty/,
120 no_warnings_returned_length => 0,
125 warning => qr/non-continuation/,
126 no_warnings_returned_length => 1,
131 warning => qr/short|1 byte, need 2/,
132 no_warnings_returned_length => 1,
137 warning => qr/overlong|2 bytes, need 1/,
138 no_warnings_returned_length => 2,
141 input => "\xe0\x80\x81",
143 warning => qr/overlong|3 bytes, need 1/,
144 no_warnings_returned_length => 3,
147 input => "\xf0\x80\x80\x81",
149 warning => qr/overlong|4 bytes, need 1/,
150 no_warnings_returned_length => 4,
152 { # Old algorithm failed to detect this
153 input => "\xff\x80\x90\x90\x90\xbf\xbf\xbf\xbf\xbf\xbf\xbf\xbf",
155 warning => qr/overflow/,
156 no_warnings_returned_length => 13,
160 # An empty input is an assertion failure on debugging builds. It is
161 # deliberately the first test.
162 require Config; import Config;
164 if ($Config{ccflags} =~ /-DDEBUGGING/) {
169 for my $test (@buf_tests) {
170 my $input = $test->{'input'};
171 my $adjustment = $test->{'adjustment'};
172 my $display = 'utf8_to_uvchr_buf("';
173 for (my $i = 0; $i < length($input) + $adjustment; $i++) {
174 $display .= sprintf "\\x%02x", ord substr($input, $i, 1);
178 my $warning = $test->{'warning'};
181 BEGIN { 'warnings'->import('utf8') if "$]" gt '5.006' }
182 $ret = &Devel::PPPort::utf8_to_uvchr_buf($input, $adjustment);
183 ok($ret->[0], 0, "returned value $display; warnings enabled");
184 ok($ret->[1], -1, "returned length $display; warnings enabled");
185 my $all_warnings = join "; ", @warnings;
186 my $contains = grep { $_ =~ $warning } $all_warnings;
187 ok($contains, 1, $display
188 . "; Got: '$all_warnings', which should contain '$warning'");
191 BEGIN { 'warnings'->unimport('utf8') if "$]" gt '5.006' }
192 $ret = &Devel::PPPort::utf8_to_uvchr_buf($input, $adjustment);
193 ok($ret->[0], 0xFFFD, "returned value $display; warnings disabled");
194 ok($ret->[1], $test->{'no_warnings_returned_length'},
195 "returned length $display; warnings disabled");